hdu 1257 最少拦截系统

http://acm.hdu.edu.cn/showproblem.php?pid=1257

先找到一个拦截系统的最低值,然后遇到不可拦截的导弹,拦截系统数量加一。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 200000
 5 using namespace std;
 6 const int inf=1<<29;
 7 
 8 int a[maxn];
 9 int n;
10 
11 int main()
12 {
13     while(scanf("%d",&n)!=EOF)
14     {
15         int cnt=1,j;
16         a[0]=inf;
17         for(int i=1; i<=n; i++)
18         {
19             int x;
20             scanf("%d",&x);
21             for(j=0; j<=cnt; j++)
22             {
23                 if(x<=a[j])
24                 {
25                     a[j]=x;
26                     break;
27                 }
28             }
29             if(j>cnt)
30             {
31                 a[++cnt]=x;
32             }
33         }
34         printf("%d\n",cnt);
35     }
36     return 0;
37 }
View Code
posted @ 2014-07-25 15:30  null1019  阅读(121)  评论(0编辑  收藏  举报