导弹

Problem Description

Long, long ago, country A invented a missle 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 from a non-decrease seqence.
But recently, the scientists found that the system is not strong enough. So they invent another missle system. The new system can launch one single missle 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 destorys 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 the height of missiles from near to far, please find the most missiles that can be destroy 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 (<=109), 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

4
5 3 2 4
3
1 1 1
0

Sample Output

3
1

Author

HYNU 


代码:


#include<stdio.h>
#include<malloc.h>
struct mm
{
   int a;// 输入的值 
   int b;// 存放长度 
}*x;
int main()
{
   int n,max,i,j;
   while(scanf("%d",&n)!=EOF&&n)
   {
      x=(mm *)malloc(sizeof(mm)*n);
      for(i=0;i<n;i++)
        {                                  // 1 2 2 3 
           scanf("%d",&x[i].a);           // 5 3 2 4                                
           x[i].b=1;//每个数对应长度为一 // 1 1 1 1  
        }   
      for(i=0;i<n;i++)
        {
           for(max=0,j=0;j<i;j++)
             {
                if(x[j].b%2==0){if(x[i].a>x[j].a&&x[j].b>max) max=x[j].b;}// 当前数长度 偶升 
                else if(x[i].a<x[j].a&&x[j].b>max)max=x[j].b; // 前数长度 奇降 
             }
           x[i].b=max+1;// 前面的最长长度加上本身
        }
      for(i=0,max=0;i<n;i++)
         if(max<x[i].b)max=x[i].b;// 找出最长长度 
      printf("%d\n",max);  
      /*
      for(i=0;i<n;i++)
        printf("%d ",x[i].b);
      */
      free(x);
   }
   return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值