CodeForces 706B Interesting drink (二分查找)
题意:给定 n 个数,然后有 m 个询问,每个询问一个数,问你小于等于这个数的数有多少个。
析:其实很简单么,先排序,然后十分查找,so easy。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 100000000000000000;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
inline LL Max(LL a, LL b){ return a < b ? b : a; }
inline LL Min(LL a, LL b){ return a > b ? b : a; }
int a[maxn]; int main(){
while(scanf("%d", &n) == 1){
for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
sort(a, a+n);
scanf("%d", &m);
while(m--){
int x;
scanf("%d", &x);
printf("%d\n", upper_bound(a, a+n, x) - a);
}
}
return 0;
}
CodeForces 706B Interesting drink (二分查找)的更多相关文章
- Codeforces - 706B - Interesting drink - 二分 - 简单dp
https://codeforces.com/problemset/problem/706/B 因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $ ...
- CodeForces - 706B Interesting drink(二分查找)
Interesting drink Problem Vasiliy likes to rest after a hard work, so you may often meet him in some ...
- 【二分】Codeforces 706B Interesting drink
题目链接: http://codeforces.com/problemset/problem/706/B 题目大意: n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m ...
- CodeForces 706B Interesting drink
排序,二分. 将$x$数组从小到大排序,每次询问的时候只要二分一下位置就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000& ...
- codeforces 706B B. Interesting drink(二分)
题目链接: B. Interesting drink 题意: 给出第i个商店的价钱为x[i],现在询问mi能在多少个地方买酒; 思路: sort后再二分; AC代码: #include <ios ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)
传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- Codeforces 475D 题解(二分查找+ST表)
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...
随机推荐
- Math.sqrt
java.lang.Math.sqrt(double a) 返回正确舍入的一个double值的正平方根.特殊情况: 如果参数是NaN或小于为零,那么结果是NaN. 如果参数是正无穷大,那么结果为正无穷 ...
- linq 之左连接
List<ArticleModel> articleList = articleRepository.GetAllArticle(); List<UsersModel> use ...
- I.MX6 bq27441 driver porting
/************************************************************************** * I.MX6 bq27441 driver p ...
- oracle中怎么查看存储过程的源码
今天想找几天前写的存储过程的源码看看,发现自己熟悉的命令怎么都不好使,要不提示标示符错误要不就是提示未选定行,通过baidu得知type跟name变量要弄成大写的.. select text from ...
- 【CSS】css各种居中方法
水平居中的text-align:center 和 margin:0 auto 这两种方法都是用来水平居中的,前者是针对父元素进行设置而后者则是对子元素.他们起作用的首要条件是子元素必须没有被flo ...
- 【转】android 自定义控件 使用declare-styleable进行配置属性(源码角度)
原文网址:http://blog.csdn.net/vipzjyno1/article/details/23696537 最近在模仿今日头条,发现它的很多属性都是通过自定义控件并设定相关的配置属性进行 ...
- css3制作优惠券
<div class="demo-container demo"><style> .demo{width:410px;} .stamp *{padding: ...
- ArcGIS AO开发高亮显示某些要素
参考代码1 ifeaturecursor pcur = ifeatureclass.search(iqueryfilter pfilter); pfilter.whereclause = strAdd ...
- [Everyday Mathematics]20150201
设数列 $\sed{a_n}$ 单调递减趋于零, 证明 $\dps{\vsm{n}a_n}$ 收敛当且仅当 $\dps{\vsm{n}3^k a_{3^k}}$ 收敛.
- [Everyday Mathematics]20150118
设 $X$ 是线性空间, $\phi_1,\cdots,\phi_n,\phi$ 是 $X$ 上的线性泛函, 试证: $$\bex \phi\in \span\sed{\phi_1,\cdots,\p ...