简单题。用一个数组存放每个拦截系统的导弹能达到的最大高度,如果后继导弹超过所有拦截系统的最大高度,那么数组就增加。只要小于某一拦截系统的话,那么就更新最大高度。

CODE:

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;

#define INF 30001
const int SIZE = 1001;

int save[SIZE];

int main()
{
    int N;
    int n;
    while(~scanf("%d", &N))
    {
        int i, j;
        int cnt = 1;
        memset(save, INF, sizeof(save));
        for(i = 0; i < N; i++)
        {
            scanf("%d", &n);
            for(j = 1; j <= cnt; j++)
            {
                if(n < save[j])               //小于某一拦截系统的最大高度 
                {
                    save[j] = n;              //更新最大高度
                    break;
                }
            }
            if(j > cnt)                      //大于所有拦截系统的最大高度 
            {
                save[++cnt] = n;
            }
        }
        printf("%d\n", cnt);
    }
    return 0
}

 

posted on 2012-07-27 21:59  有间博客  阅读(198)  评论(0编辑  收藏  举报