[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;
}
[CodeForces 372A] Counting Kangaroos is Fun的更多相关文章
- 【Codeforces 372A】Counting Kangaroos is Fun
[链接] 我是链接,点我呀:) [题意] 如果a[i]*2<=a[j]那么i袋鼠可以装进j袋鼠里面 每只袋鼠都只能装一只袋鼠 [题解] 假设最后的方案是(ai,bi) 这里(ai,bi)表示下标 ...
- CodeForces 372 A. Counting Kangaroos is Fun
题意,有n只袋鼠,没每只袋鼠有个袋子,大小为si,一个袋鼠可以进入另外一个袋鼠的袋子里面,当且仅当另一个袋鼠的袋子是他的二倍或二倍一上,然后中国袋鼠就是不可见的,不能出现多个袋鼠嵌套的情况.让你求最少 ...
- Codeforces 893E - Counting Arrays
893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...
- cf C. Counting Kangaroos is Fun
http://codeforces.com/contest/373/problem/C 贪心,先排序,然后从n/2位置倒着找每一个可不可以放到别的袋鼠内. #include <cstdio> ...
- Codeforces 372B Counting Rectangles is Fun
http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下 ...
- Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论
题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...
- Codeforces 372B Counting Rectangles is Fun:dp套dp
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...
- Counting Kangaroos is Fun 求最少可见袋鼠数
Description There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaro ...
- A. Counting Kangaroos is Fun(贪心)
#include<stdio.h> #include<algorithm> using namespace std; ]; int main() { int i,n,high; ...
随机推荐
- hibernate12--缓存
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN&q ...
- 剑指offer——python【第31题】整数1出现的次数
题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...
- python中字符串格式化的四种方法
name = "huangemiling" age= 10 address = 'nanjing' print("My name is %s,age is %d,I co ...
- css的position,float属性的理解
我们知道,html是按照普通流来加载的,这个时候我们有些需求就不好实现.因此出现了非普通流: 1.普通流:按照顺序正常的排列,长度或不够就往下挤.position默认的static 2.非普通流:脱离 ...
- 注意兼容浮点运算误差 0.7 + 0.1 ==0.8 为false
所以比较 汇总或者计算的时候注意确定精度0.7 + 0.1 ==0.8 换成 Math.abs(0.7 + 0.1 ==0.8)<0.0001参考下
- leetcode-Given a binary tree, find its minimum depth
第一题 Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the s ...
- Android基础总结+SQlite数据库【申明:来源于网络】
Android基础总结+SQlite数据库[申明:来源于网络] 基础总结篇之一:Activity生命周期:http://blog.csdn.net/liuhe688/article/details/6 ...
- 使用iostat查看磁盘使用情况
Ⅰ.iostat安装 [root@VM_42_63_centos ~]# yum install -y sysstat Ⅱ.玩一手 [root@VM_42_63_centos ~]# iostat - ...
- SyntaxError:unexpected EOF while parsing(<string,line 0>)
在python+Django中出现报错:(上图) 经断点发现:python内置函数eval在处理空字符串时会返回EOF错误,判断后解决
- 关于win10安装NET Framework 3.5,错误87的终极解答0x80070057
链接:https://pan.baidu.com/s/1z6fZLQTW_b7Qe5tF0xNEuw 密码:ef0d 所有错误87的朋友,你们这样试试,错误原因主要是CAB文件没解压造成.请按以下步骤 ...