codeforces706B Interesting drink 排序+二分查找
来源:互联网 发布:sql datepart 编辑:程序博客网 时间:2024/05/06 19:14
从大到小排个序,二分查找比输入的数大的第一个数,然后这个数的位置下标减一即输出
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <cstdlib>#include <algorithm>using namespace std;const int maxn = 100000;int a[maxn + 5];int main(){int n, q, tmp;cin >> n;for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}sort(a + 1, a + n + 1);cin >> q;while (q--) {scanf("%d", &tmp);int l, r;l = 1; r = n;while (l <= r) {int mid = (l + r) / 2;if (a[mid] > tmp) {r = mid - 1;}else {l = mid + 1;}}printf("%d\n", l - 1);}return 0;}
0 0
- codeforces706B Interesting drink 排序+二分查找
- codeforces706B(二分)之Interesting drink
- interesting drink(二分)
- Interesting drink--二分
- 【Codeforces Round 367 (Div 2) B】【二分查找】Interesting drink
- Codeforces 706B:Interesting drink(二分+排序)
- codeforces 706B B. Interesting drink (二分)
- 【Codeforces】-706B-Interesting drink(二分)
- 【二分】Codeforces 706B Interesting drink
- Codeforces 706B Interesting drink 【二分】
- Codeforces #367 B. Interesting drink(二分)
- Interesting drink
- Interesting drink
- Codeforces Round #367 (Div. 2) B Interesting drink【二分】
- Codeforces Round #367 (Div. 2) B Interesting drink(二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink(二分)
- win7下对批量文件重命名(截取原始文件名中的部分作新名字)
- Android编程至高武学之《如来神掌》第一式~佛光初现
- Express介绍
- hadoop集群环境的搭建
- android 自定义相机(三星遇花屏)
- codeforces706B Interesting drink 排序+二分查找
- TODO-2:浏览器唤醒APP
- nginx 禁止直接访问IP
- UIAppearance
- mybatis里面 ${} 和 #{}区别
- Mysql插入语句之value与values区别
- java线程池实例
- hdu1257 导弹拦截系统(LIS)
- angularJS页面跳转后自动弹出对话框