最少拦截系统-贪心
2013-06-04 14:36
183 查看
最少拦截系统
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11874 Accepted Submission(s): 4673
Problem Description
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
#include <iostream> #include <stdio.h> #include <algorithm> using namespace std; struct M{ int index,h; bool v; }; bool cmp(const M & m1,const M & m2){ return m1.h > m2.h; } int n; M ms[100000]; int main() { //freopen("in.txt","r", stdin); while(cin >> n){ for(int i=0; i<n; i++){ ms[i].index = i; ms[i].v = false; cin >> ms[i].h; } sort(ms, ms+n, cmp); int cnt = 0,ans = 0; int pre; while(cnt < n){ int i; for(i=0; i<n; i++){ if(!ms[i].v){ ans++; pre = i; ms[i].v = true; cnt++; break; } } if(cnt >= n) break; for(int j=i+1; j<n; j++){ if(ms[j].index > ms[pre].index && !ms[j].v) { pre = j; ms[j].v = true; cnt++; } } } cout << ans << endl; } return 0; }
相关文章推荐
- ACM:最少拦截系统:贪心思想
- HDOJ.1257 最少拦截系统 (贪心)
- HDU 1257 最少拦截系统(最长上升子序列+贪心)
- hdoj 1257 最少拦截系统【贪心】
- HDU1257 最少拦截系统 (贪心+STL+二分)
- 最少拦截系统(杭电1257)(DP)+(贪心)
- hdu 1257 最少拦截系统 贪心
- 最少拦截系统(杭电1257)(DP)+(贪心)
- HDU1257 最少拦截系统(贪心)
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
- HDU-1257 最少拦截系统 贪心/DP 最长上升子序列的长度==最长不上升子序列的个数?
- hdu 1257 最少拦截系统(简单dp+贪心)
- HDU - 1257 最少拦截系统(贪心 OR LIS)
- 最少拦截系统,简单dp,(学长说这是贪心?!。。。。。。也是醉了)
- hdu1257 最少拦截系统(贪心)
- hdu 1257 最少拦截系统(贪心)
- hdu1257 最少拦截系统 (贪心)
- 【HDU 1257 】 最少拦截系统 【贪心】
- HDU 1257 最少拦截系统 (贪心---求最长递减序列(不连续的))
- 贪心专练6 最少拦截系统