hdu 1257 最少拦截系统(简单贪心)

时间:2023-03-09 23:39:27
hdu 1257 最少拦截系统(简单贪心)

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

虽然分类是dp感觉还是贪心

比较水

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = +;
int d[maxn]; //d数组存储一套系统的目前的发射的最小的高度 int main()
{
int n, i, x, cou, j;
while(~scanf("%d", &n))
{
cou = ;
for(i = ; i <= n; i++)
{
scanf("%d", &x);
sort(d, d+cou); //排序,先找最小的那一个
for(j = ; j < cou; j++)
if(d[j]>x)
{
d[j] = x;
break;
}
if(j == cou) //如果目前所有系统都达不到高度,再造一个系统
d[cou++] = x;
}
cout<<cou<<endl;
}
return ;
}