X-man

导航

A. Counting Kangaroos is Fun(贪心)

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

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

posted on 2013-12-16 22:22  雨钝风轻  阅读(409)  评论(0编辑  收藏  举报