2904.最少拦截系统

/*
思路:输入一个导弹,与拦截系统比一次,系统数组中是从小到大排序的,从前面开始遇到能拦截的(就是小于拦截系统的)就拦截,系统变换,
若所有拦截系统都拦截不下,再重新建一个拦截系统。
*/
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int main()
 6 {
 7    int n;
 8    int a[1024],b[1024];     //a数组保存导弹,b数组保存拦截系统。
 9    while(~scanf("%d",&n))
10    {
11        memset(b,0,sizeof(b));
12        int l=0;
13        scanf("%d",&a[0]);   //刚开始没有拦截系统,必须先建一个。
14        b[0]=a[0];
15        for(int j=1;j<n;j++)
16        {
17            scanf("%d",&a[j]);
18            for(int i=0;i<=l;i++)
19            {
20                if(b[i]>=a[j])        //能拦截的就拦截。
21                {
22                    b[i]=a[j];
23                    break;
24                }
25                if(b[i]<a[j])            
26                {
27                    if(i==l)                 //所有的都不能拦截,再建一个拦截系统。
28                    {
29                     l++;
30                     b[l]=a[j];
31                    }
32                    else                    //这个拦截系统不行,换下一个。
33                    continue;
34                }
35            }
36        }
37          //for(int i=0;i<=l;i++)
38             //printf("%d ",b[i]);
39        printf("%d\n",l+1);
40    }
41    return 0;
42 }

 

 

posted on 2016-04-14 21:12  走-走  阅读(228)  评论(0编辑  收藏  举报