博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Missile
阅读量:4323 次
发布时间:2019-06-06

本文共 1872 字,大约阅读时间需要 6 分钟。

Problem Description

Long, long ago, country A invented a missile system to destroy the missiles from their enemy. That system can launch only one missile to destroy multiple missiles if the heights of all the missiles form a non-decrease sequence. But recently, the scientists found that the system is not strong enough. So they invent another missile system. The new system can launch one single missile to destroy many more enemy missiles. Basically, the system can destroy the missile from near to far. When the system is begun, it chooses one enemy missile to destroy, and then destroys a missile whose height is lower and farther than the first missile. The third missile to destroy is higher and farther than the second missile… the odd missile to destroy is higher and farther than the previous one, and the even missile to destroy is lower and farther than the previous one. Now, given you a list of the height of missiles from near to far, please find the most missiles that can be destroyed by one missile launched by the new system.

Input

The input contains multiple test cases. In each test case, first line is an integer n (0<n<=1000), which is the number of missiles to destroy. Then follows one line which contains n integers (<=10^9), the height of the missiles followed by distance. The input is terminated by n=0

Output

For each case, print the most missiles that can be destroyed in one line.

Sample Input

45 3 2 431 1 10 #include
#include
int p[1005]; int sum[1005]; int main() {
    int n,i;  while(scanf("%d",&n)&&n)  {
  for(i=0;i
=0;i--)   {
            if(i==n-1)  sum[i]=1;    else if(i==n-2)    {
    if(p[i]>p[i+1]) sum[i]=2;     else sum[i]=1;    }    else    {
               if(p[i]>p[i+1]&&p[i+1]

转载于:https://www.cnblogs.com/ffhuguang/archive/2013/04/21/3034736.html

你可能感兴趣的文章
小白的python进阶历程------05.占位符
查看>>
CF414BMashmokh and ACMDP
查看>>
Notepad++ 通过g++编译
查看>>
JAVA基础2——类初始化相关执行顺序
查看>>
转:Zend Framework 重定向方法(render, forward, redirect)
查看>>
Linux下查看磁盘与目录的容量——df、du
查看>>
关于日记app的思考
查看>>
使用sencha的cmd创建项目时提示找不到\Sencha\Cmd\repo\.sencha\codegen.json
查看>>
如何快速启动一个Java Web编程框架
查看>>
MSP430单片机存储器结构总结
查看>>
文本框过滤特殊符号
查看>>
教育行业安全无线网络解决方案
查看>>
7个杀手级的开源监测工具
查看>>
软件架构学习小结
查看>>
C语言实现UrlEncode编码/UrlDecode解码
查看>>
返回用户提交的图像工具类
查看>>
树链剖分 BZOJ3589 动态树
查看>>
挑战程序设计竞赛 P131 区间DP
查看>>
【例9.9】最长公共子序列
查看>>
NSFileManager打印目录下的文件的函数
查看>>