【二分】Codeforces 706B Interesting drink
2016-08-16 23:36
302 查看
题目链接:
http://codeforces.com/problemset/problem/706/B
题目大意:
n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m(1≤m≤100 000)天,每天有Cj的钱,问每天可以负的起的商店数。
题目思路:
【二分】
排个序,二分。
http://codeforces.com/problemset/problem/706/B
题目大意:
n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m(1≤m≤100 000)天,每天有Cj的钱,问每天可以负的起的商店数。
题目思路:
【二分】
排个序,二分。
// //by coolxxx // #include<iostream> #include<algorithm> #include<string> #include<iomanip&g 4000 t; #include<memory.h> #include<time.h> #include<stdio.h> #include<stdlib.h> #include<string.h> //#include<stdbool.h> #include<math.h> #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abs(a) ((a)>0?(a):(-(a))) #define lowbit(a) (a&(-a)) #define sqr(a) ((a)*(a)) #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b)) #define eps (1e-8) #define J 10000000 #define MAX 0x7f7f7f7f #define PI 3.1415926535897 #define N 100004 using namespace std; typedef long long LL; int cas,cass; int n,m,lll,ans; int a ; bool cmp(int aa,int bb) { return aa<bb; } int work(int v) { int l=0,r=n,mid; while(l<r) { mid=(l+r+1)>>1; if(v>=a[mid])l=mid; else r=mid-1; } return r; } int main() { #ifndef ONLINE_JUDGE // freopen("1.txt","r",stdin); // freopen("2.txt","w",stdout); #endif int i,j,x,v; // for(scanf("%d",&cas);cas;cas--) // for(scanf("%d",&cas),cass=1;cass<=cas;cass++) // while(~scanf("%s",s)) while(~scanf("%d",&n)) { for(i=1,x=0;i<=n;i++) { scanf("%d",&a[i]); x=max(a[i],x); } sort(a+1,a+1+n,cmp); scanf("%d",&m); for(i=1;i<=m;i++) { scanf("%d",&v); if(v>=x)printf("%d\n",n); else printf("%d\n",work(v)); } } return 0; } /* // // */
相关文章推荐
- 【codeforces 782B】The Meeting Place Cannot Be Changed(二分)
- codeforces 493C Vasya and Basketball(二分)
- Codeforces 237C:Primes on Interval(素数打表+二分)
- codeforces 808D Array Division(二分+思维)
- Codeforces-786C-Till I Collapse(二分剪枝)
- CodeForces - 620D Professor GukiZ and Two Arrays 二分 | 双指针 STL
- Codeforces 812C Sagheer and Nubian Market[二分]
- CodeForces 627D Preorder Test(树形DP+二分)
- Codeforces 702 B. Powers of Two(二分)
- 文章标题 codeforces 75C:Modified GCD (二分+最大公因数)
- Codeforces 589G Hiring(BIT + 二分)
- codeforces 817C Really Big Numbers 二分
- Codeforces 387D George and Interesting Graph【思维+二分匹配】
- codeforces 734 C. Anton and Making Potions (二分 STL)
- codeforces 74B. Arpa’s obvious problem and Mehrdad’s terrible solution (异或+二分STL)
- 【Codeforces】-706B-Interesting drink(二分)
- Codeforces 670 D1. Magic Powder - 1【二分查找】
- codeforces 702C Cellular Network 二分
- Codeforces 920G - List Of Integers 【容斥+二分】
- Codeforces 689D RMQ+二分