题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257
题意:略
题解:贪心策略:找能拦截到的高度最小的拦截导弹拦截,如果没有,则新发射一枚导弹。用vector向量存拦截导弹,最后向量的大小即是拦截导弹的数量
AC代码:
#include<iostream>
#include"vector"
using namespace std;
int main()
{
int n;
while(scanf("%d",&n) !=EOF){
vector<int> dao;
int d;
for(int i = 0;i<n;i++){
cin>>d;
int j;
for( j = 0;j<dao.size();j++){
if(dao[j] > d ){
dao[j] = d;
break;
}
}
if(j == dao.size()){
dao.push_back(d);
}
}
cout<<dao.size()<<endl;
}
return 0;
}
小结:略