#include <iostream>
#include <algorithm>
using namespace std;
//题意:求非递增序列组的个数
//简单贪心
#define NSIZ 300000
int flag[NSIZ];
int arr[NSIZ];
void select(int arr[], int s, int n)
{
int i = s, j = s;
flag[i] = 1;
++i;
for(;i < n;++i)
{
if(!flag[i] && arr[i] <= arr[j])
{
flag[i] = 1;
j = i;
}
}
}
int main()
{
int n, k;
int i, sum;
while(scanf("%d", &n) != EOF)
{
for(i = 0;i < n; ++i)
{
scanf("%d", &arr[i]);
}
memset(flag, 0, sizeof(flag));
sum = 0;
for(i = 0;i < n; ++i)
{
if(!flag[i])
{
sum++;
select(arr, i, n);
}
}
printf("%d\n", sum);
}
return 0;
}
hdu1257最少拦截系统【贪心算法】
最新推荐文章于 2021-03-01 16:23:45 发布