Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
来源:互联网 发布:python的print不换行 编辑:程序博客网 时间:2024/05/19 16:20
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xicoins.
Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent mi coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains n integers xi (1 ≤ xi ≤ 100 000) — prices of the bottles of the drink in the i-th shop.
The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink.
Then follow q lines each containing one integer mi (1 ≤ mi ≤ 109) — the number of coins Vasiliy can spent on the i-th day.
Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day.
53 10 8 6 114110311
0415
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop.
题解:二分。
AC代码:
#pragma comment(linker, "/STACK:102400000,102400000")//#include<bits/stdc++.h>#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<cstring>#include<vector>#include<map>#include<cmath>#include<queue>#include<set>#include<stack>using namespace std;typedef long long ll;typedef unsigned long long ull;#define mst(a) memset(a, 0, sizeof(a))#define M_P(x,y) make_pair(x,y) #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) #define lson x << 1, l, mid #define rson x << 1 | 1, mid + 1, r const int lowbit(int x) { return x&-x; } const double eps = 1e-8; const int inf = 0x7FFFFFFF; const int MOD = 1e9 + 7; const ll mod = (1LL<<32);const int N = 2010; template <class T1, class T2>inline void getmax(T1 &a, T2 b) { if (b>a)a = b; } template <class T1, class T2>inline void getmin(T1 &a, T2 b) { if (b<a)a = b; }int read(){int v = 0, f = 1;char c =getchar();while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();return v*f;}int a[100010];int main() {//freopen("in.txt","r",stdin);int n;n=read();for(int i=0;i<n;i++){cin>>a[i];}sort(a,a+n); int q;q=read();while(q--){int m;int sum=0;m=read();printf("%d\n",upper_bound(a,a+n,m)-a);}return 0;}/*int main(){int n,i,j,k,num,m;while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);scanf("%d",&m);while(m--){scanf("%d",&num); if(num<a[1]) printf("0\n"); else if(num>=a[n]) printf("%d\n",n); else { int left=1; int right=n; int mid; int ans; while(left<=right) { mid=(left+right)/2; if(a[mid]<=num) { ans=mid; left=mid+1;}else{right=mid-1;}}printf("%d\n",ans);}}}return 0;}*/
- 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【二分】
- 【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
- Codeforces Round #367 (Div. 2) B. Interesting drink 离线操作
- Codeforces #367 B. Interesting drink(二分)
- Codeforces #367(Div.2)B Interesting drink【树状数组】
- 【Codeforces】-706B-Interesting drink(二分)
- codeforces 706B B. Interesting drink (二分)
- codeforces-367#B. Interesting drink
- Codeforces 706B:Interesting drink(二分+排序)
- 【二分】Codeforces 706B Interesting drink
- Maple数据分析 级数与拟合
- Java Script-错误
- iOS开发-UIView之动画效果的实现方法(合集)
- 更改服务器图片尺寸
- s3c2440 uda1341声卡驱动与madplay播放器移植
- Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
- qq邮箱发邮件
- Android进程间通讯之AIDL
- LCS算法
- JQuery(入门一)
- VS2015卸载与系统盘扩展
- httpclient访问https网站失败(peer not authenticated)
- Actor模型的本质
- word2vec的使用参数解释和应用场景