cf C. Counting Kangaroos is Fun

http://codeforces.com/contest/373/problem/C

贪心,先排序,然后从n/2位置倒着找每一个可不可以放到别的袋鼠内。

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <algorithm>

 4 #define maxn 5000001

 5 using namespace std;

 6 

 7 int a[maxn];

 8 bool vis[maxn];

 9 int n;

10 

11 int main()

12 {

13     while(scanf("%d",&n)!=EOF)

14     {

15         memset(vis,false,sizeof(vis));

16         for(int i=0; i<n; i++)

17         {

18             scanf("%d",&a[i]);

19         }

20         sort(a,a+n);

21         int j=n-1;

22         int ans=0;

23         for(int i=n/2-1; i>=0; i--)

24         {

25             if(a[j]>=2*a[i])

26             {

27                 j--;

28                 ans++;

29             }

30         }

31         printf("%d\n",n-ans);

32     }

33     return 0;

34 }
View Code

 

你可能感兴趣的:(count)