[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; ...
随机推荐
- 8、路由 router
路由:router 用户功能 /user ----> index.html /user/login ----> login.html /user/reg ----> reg.html ...
- JavaScript---设计模式总结
写了两篇设计模式的东西后,感觉不是很完美,决定闭关修炼,同时写下笔记 重申:设计模式很有用! 这里列一个设计模式的目录防止漏了某个东西(未完成的没有链接) 单例模式 策略模式 代理模式 迭代器模式 发 ...
- Codeforces 1114 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1114 A - Got Any Grapes? 题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄.紫葡萄和黑葡萄,甲乙丙三个人至少要 ...
- [No000018A]改善C#程序的建议11-20
建议11:区别对待 == 和Equals CLR中将“相等性”分为两类:1.值相等性:两个变量包含的数值相等.2.引用相等性:两个变量引用的是内存中的同一个对象. 但并不是所有的类型的比较都是按照其本 ...
- 添加一个Activity
#Android中增加一个Activity 1. 在AndroidManifest.xml中增加: <activity android:name="com.example.NewAct ...
- 洛谷P2743 乐曲主题Musical Themes [USACO5.1] SA
正解:SA 解题报告: 传送门 这题三个条件嘛,那就一个个考虑下都解决了就把这题解决了嘛QwQ 那就直接分别针对三个条件写下各个击破就欧克辣? 1)长度大于等于5:求出答案之后和5比大小 2)不能有公 ...
- 安装mysql服务时提示“找不到msvcp140.dll”
没有安装VC++2015版运行库导致的(Microsoft Visual C++ 2015 Redistributable),下载地址https://www.microsoft.com/en-us/d ...
- Cestos7安装Elasticsearch5.4.3
Elasticsearch及配件下载地址:https://www.elastic.co/cn/downloads 为了简单起见,我们使用tar文件. 在/usl下创建elk目录 一.安装elastic ...
- React-Router4.x中文文档
以下为翻译的中文API(水平有限,凑合看,欢迎纠正补充~) <BrowserRouter> 使用HTML5历史记录API(pushState,replaceState和popstate事件 ...
- Android字符串判断是否包含中文
// 判断一个字符是否是中文 public boolean isChinese(char c) { return c >= 0x4E00 && c <= 0x9FA5;// ...