HDU-1257 最少拦截系统
来源:互联网 发布:钢筋笼计算软件 编辑:程序博客网 时间:2024/06/18 18:45
Problem Description
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
Source
浙江工业大学第四届大学生程序设计竞赛
贪心~求最长递减子序列
第一种方法:
#include <iostream>#include <cstdio>#include <set>using namespace std;int main(int argc, char const *argv[]){ int n,a[1005],b[1005]; while(cin>>n) { for(int i=0;i<n;i++) { cin>>a[i]; b[i]=1; } for(int i=1;i<n;i++) { for(int j=0;j<i;j++) { if(a[j]<a[i]&&b[j]+1>b[i]) { b[i]=b[j]+1; } } } int max=-1; for(int i=0;i<n;i++) { if(b[i]>max) max=b[i]; } cout<<max<<endl; } return 0;}
第二种:利用set解决,和列车调度问题很像
#include <iostream>#include <cstdio>#include <set>using namespace std;int main(int argc, char const *argv[]){ int n,v; while(cin>>n) { set<int>s; while(n--) { cin>>v; if(s.lower_bound(v)!=s.end()) { s.erase(s.lower_bound(v)); } s.insert(v); } printf("%d\n",s.size()); } return 0;}
阅读全文
0 0
- hdu 1257 最少拦截系统
- 最少拦截系统 hdu 1257
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- 【8086汇编】基础排序之希尔排序
- ubuntu下php环境安装
- 存储系统
- HDU
- Ubuntu16.04+Cuda8.0+1080ti+caffe+免OpenCV+faster-rcnn教程
- HDU-1257 最少拦截系统
- 封斋第一天
- SSM-maven-IntelliJ搭建
- 解决VS Code保存时候自动格式化
- iOS攻防
- POJ
- 【XML解析】(2)利用DOM解析技术对XML文档进行增删改查操作
- android 导入类报错,找不到符号
- SSL certificate problem: unable to get local issuer certificate 解决方法