hdu 1257 最少拦截系统

本文介绍了一种解决拦截导弹问题的算法实现。通过寻找拦截系统的最低值并递增计数来处理不可拦截的导弹,使用动态规划思想进行优化。代码采用C++编写,实现了高效的求解过程。

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

转载于:https://www.cnblogs.com/fanminghui/p/3868179.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值