A. Counting Kangaroos is Fun(贪心)

时间:2023-12-16 16:27:56
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[];
int main()
{
int i,n,high;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int ans=n;
high=n-;
for(i=n/-;i>=;i--)//i=n/2-1容易出错
{
if(a[i]*<=a[high])
{
ans--;
high--;
}
}
printf("%d\n",ans);
}
return ;
}

从中间开始贪心Each kangaroo can hold at most one kangaroo