其他分享
首页 > 其他分享> > [CodeForces 372A] Counting Kangaroos is Fun

[CodeForces 372A] Counting Kangaroos is Fun

作者:互联网

题目链接:http://codeforces.com/problemset/problem/372/A
二分思想
AC代码:

#include <cstdio>
#include <algorithm>

using namespace std;

int arr[500005];

int main() {
    int n;
    while(scanf("%d",&n) != EOF) {
        for(int i = 0;i < n;i++) {
            scanf("%d",&arr[i]);
        }
        sort(arr,arr+n);
        int l = 0,r = n/2,ans = 0;
        while(l < n/2) {
            while(r < n && arr[r] < 2 * arr[l]) {
                r++;
            }
            if(arr[r] >= 2 * arr[l]) {
                r++;
                ans++;
            }
            l++;
        }
        printf("%d\n",n-ans);
    }
    return 0;
}

标签:arr,int,scanf,++,while,ans,Fun,Counting,Kangaroos
来源: https://www.cnblogs.com/youpeng/p/10743360.html