二分——CF154,Div.2
来源:互联网 发布:virtualbox ubuntu 卡 编辑:程序博客网 时间:2024/05/22 13:31
//http://www.codeforces.com/contest/253/problem/B//二分#include <algorithm>#include <iostream>#include <cstdio>using namespace std;int a[155660],n;int lower_bound2(int v){ int x=1; int y=n; int m;// cout<<"v is "<<v<<endl; while(x<y){ m=(x+y)/2; if(a[m]>=v) y=m; else x=m+1; }// cout << "fasdf"<<" "<<x<<endl; return x;}int main(){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int ans; while (cin>>n){ for(int j =1;j<n+1;j++) cin>>a[j]; sort(a+1,a+n+1); a[0]=-9119999; a[n+1]=99999999; ans=9999999; for (int j=n;j>0;j--) if(a[j]&1) ans=min(ans,n-j-1+lower_bound2(a[j]/2+1)); else ans=min(ans, n-j-1+lower_bound2(a[j]/2)); cout<<ans<<endl<<endl; } return 0;}
解法二
//http://www.codeforces.com/contest/253/problem/B//二分#include <algorithm>#include <iostream>#include <cstdio>using namespace std;int a[155660],n;int upper_bound2(int v){ int x=0; int y=n; int m; while(x<y){ m=(x+y)/2; if(a[m]<=v) x=m+1; else y=m; }// cout<<x<<endl; return x;}int main(){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int ans; while (cin>>n){ for(int j =0;j<n;j++) cin>>a[j]; sort(a,a+n); a[n]=-99999999; ans=9999999; for (int j=0;j<n;j++) ans=min(ans,n+j-upper_bound2(2*a[j])); cout<<ans<<endl; } return 0;}
- 二分——CF154,Div.2
- 二分——Codeforces Round #377 (Div. 2) D
- Codeforces Round #283 (Div. 2) D Tennis Game ——枚举,二分
- Codeforces Round #291 (Div. 2)D.R2D2 and Droid Army——RMQ+二分
- Codeforces Round #398 (Div. 2) D. Cartons of milk —— 二分
- Codeforces Round #143 (Div. 2) C. To Add or Not to Add —— 二分
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分
- Codeforces Round #211 (Div. 2)(二分贪心)
- Codeforces Round #251 (Div. 2) D 二分
- Codeforces Round #262 (Div. 2) 总结:二分
- Codeforces Round #350 (Div. 2) (二分答案)
- Codeforces Round #352 (Div. 2) D 二分
- Codeforces#354C (Div. 2) 二分答案
- Codeforces Round #361 (Div. 2) C 二分
- Codeforces Round #321 (Div. 2) B 二分
- Codeforces Round #377 (Div. 2) D 二分
- Codeforces Round #360 (Div. 2)——C. NP-Hard Problem(BFS染色判二分图)
- Codeforces Round #350 (Div. 2) D2 Magic Powder - 2【二分】
- codeplex上发现的好东西
- 我的SEO之路2013年1月29日关于网站被k恢复
- 怎么查看端口占用情况
- CSS+JS方法去除点击链接,按钮时出现的虚线框
- FusionCharts生成Flash图表常见问题FAQ
- 二分——CF154,Div.2
- 小米手机1 BUG 二点
- 禁用WAS自动生成 LTPA 密钥,解决密钥过期问题
- NAT和NAT穿透介绍
- map的key元素为结构体时该结构体需重截操作符<
- 安装Adobe Flash Player证书验证失败
- 删数问题(贪心)
- struts2 rest插件详细说明
- Markdown