Codeforces Round #154 (Div. 2)——B
来源:互联网 发布:powermill编程视频教程 编辑:程序博客网 时间:2024/06/02 08:40
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
The first line contains integer n (2 ≤ n ≤ 105) — the number of measurements Vasya made. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
Print a single integer — the minimum number of results Vasya will have to remove.
64 5 3 8 3 7
2
44 3 2 4
0
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;#define maxn 100005int c[maxn];int main(){ freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); int n,i,j; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",c+i); sort(c,c+n); int ans=0; for(i=0,j=0;i<n;i++) { while(j<n&&c[j]<=2*c[i]) j++; ans=max(ans,j-i); } printf("%d",n-ans); return 0;}
- Codeforces Round #154 (Div. 2)——B
- Codeforces Round #156 (Div. 2)——B
- Codeforces Round #151 (Div. 2)——B
- Codeforces Round #152 (Div. 2)——B
- Codeforces Round #149 (Div. 2)——B
- Codeforces Round #146 (Div. 2)——B
- Codeforces Round #144 (Div. 2)——B
- Codeforces Round #142 (Div. 2)——B
- Codeforces Round #157 (Div. 2)——B
- Codeforces Round #134 (Div. 2)——B
- Codeforces Round #141 (Div. 2)——B
- Codeforces Round #140 (Div. 2)——B
- Codeforces Round #137 (Div. 2)——B
- Codeforces Round #136 (Div. 2)——B
- Codeforces Round #135 (Div. 2)——B
- Codeforces Round #124 (Div. 2)——B
- Codeforces Round #123 (Div. 2)——B
- Codeforces Round #117 (Div. 2)——B
- 常用函数解析
- RT3070wifi模块的移植
- ios中设置的添加
- 几个优秀的js框架的license问题,付费,版权,侵权
- PlantUML —— 应用于 Eclipse 的简单快速的 UML 编辑软件
- Codeforces Round #154 (Div. 2)——B
- jquery日历控件推荐,看看老外们的功底
- Design Pattern:Singleton
- const 和volatile
- 网卡声卡驱动更新失败,并导致原驱动失效
- cocos2d-x开发的几点总结
- 《OpenGL 3 & DirectX 11: The War Is Over》:绘图API 终战之日?
- Win8 自定义TimePicker --- 用户控件
- js判断字符是否是汉字的几种方法