zoukankan      html  css  js  c++  java
  • 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-ans);
    32     }
    33     return 0;
    34 }
    View Code
  • 相关阅读:
    while循环学习之统计流量
    MySQL的启动脚本
    UVA 725 Division
    UVA 712 S-tree
    UVA 514
    字典树
    UVA 1595 multimap 的应用
    C++ map 和 multimap
    浮点数
    UVA 227
  • 原文地址:https://www.cnblogs.com/fanminghui/p/4079818.html
Copyright © 2011-2022 走看看