题目链接: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;
}

[CodeForces 372A] Counting Kangaroos is Fun的更多相关文章

  1. 【Codeforces 372A】Counting Kangaroos is Fun

    [链接] 我是链接,点我呀:) [题意] 如果a[i]*2<=a[j]那么i袋鼠可以装进j袋鼠里面 每只袋鼠都只能装一只袋鼠 [题解] 假设最后的方案是(ai,bi) 这里(ai,bi)表示下标 ...

  2. CodeForces 372 A. Counting Kangaroos is Fun

    题意,有n只袋鼠,没每只袋鼠有个袋子,大小为si,一个袋鼠可以进入另外一个袋鼠的袋子里面,当且仅当另一个袋鼠的袋子是他的二倍或二倍一上,然后中国袋鼠就是不可见的,不能出现多个袋鼠嵌套的情况.让你求最少 ...

  3. Codeforces 893E - Counting Arrays

    893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...

  4. cf C. Counting Kangaroos is Fun

    http://codeforces.com/contest/373/problem/C 贪心,先排序,然后从n/2位置倒着找每一个可不可以放到别的袋鼠内. #include <cstdio> ...

  5. Codeforces 372B Counting Rectangles is Fun

    http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下 ...

  6. Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论

    题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...

  7. Codeforces 372B Counting Rectangles is Fun:dp套dp

    题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...

  8. Counting Kangaroos is Fun 求最少可见袋鼠数

    Description There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaro ...

  9. A. Counting Kangaroos is Fun(贪心)

    #include<stdio.h> #include<algorithm> using namespace std; ]; int main() { int i,n,high; ...

随机推荐

  1. 常用基础Linux操作命令总结与hadoop基础操作命令

    cd命令:切换目录 (1)切换到目录 /usr/local cd /usr/local (2)去到目前的上层目录 cd .. (3)回到自己的主文件夹 cd ~ ls命令:查看文件与目录 (4)查看目 ...

  2. Grunt Bower构建前端

    Grunt + Bower—前端构建利器   目前比较流行的WEB开发的趋势是前后端分离.前端采用重量级的Javascript框架,比如Angular,Ember等,后端采用restful API的W ...

  3. 用SQL快速删除U8账套

    一.问题提出 通过"系统管理"来删除999账套,首先要求你备份然后才能删除.头痛的是: 1)备份需要发费很长的时间,特别是账套数据文件比较大时. 2)备份时,你的本本基本处于死机状 ...

  4. JavaScript基础知识(数据类型)

    数据类型 布尔:true/fasle console.log(typeof true);// "boolean" Number : true -->1 false --> ...

  5. stm8s 引脚电平异常

    特别注意: 1.有iic 的引脚为了兼容电平,一般来说都是可忍受电平,同时该引脚也将被去除推挽输出和强输出能力,甚至是上拉,使用时候特别注意,这种引脚在stm8上非常常见 2.stm引脚对电平不匹配非 ...

  6. Docker数据卷

    1.volume操作命名:docker volume Usage:    docker volume COMMAND Manage Docker volumes Options:       --he ...

  7. SQL[Err] ORA-00979: not a GROUP BY expression

    Oracle中group by用法 not a GROUP BY expression异常产生是因为group by用法的问题. 在使用group by 时,有一个规则需要遵守,即出现在select列 ...

  8. 6、Flutter Error waiting for a debug connection: ProcessException: adb did not report f(转)

    1.错误信息 Error waiting for a debug connection: ProcessException: adb did not report forwarded port 2.解 ...

  9. Mysql数据库配置参数详解大全

    名称 是否需要重启 值 允许值 描述 auto_increment_increment 否 1 1-65,535 auto_increment_increment和auto_increment_off ...

  10. 各操作系统安装redis

    mac系统安装redis 注:Mac操作亲测可用,其他系统的安装均从菜鸟教程转载而来,未测试是否可用 一.下载 打开官网:https://redis.io/ Download---Stable---D ...