题意:给定 n 个数,然后有 m 个询问,每个询问一个数,问你小于等于这个数的数有多少个。

析:其实很简单么,先排序,然后十分查找,so easy。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <stack>
  15. using namespace std;
  16.  
  17. typedef long long LL;
  18. typedef pair<int, int> P;
  19. const int INF = 0x3f3f3f3f;
  20. const double inf = 0x3f3f3f3f3f3f;
  21. const LL LNF = 100000000000000000;
  22. const double PI = acos(-1.0);
  23. const double eps = 1e-8;
  24. const int maxn = 1e5 + 5;
  25. const int mod = 1e9 + 7;
  26. const char *mark = "+-*";
  27. const int dr[] = {-1, 0, 1, 0};
  28. const int dc[] = {0, 1, 0, -1};
  29. int n, m;
  30. inline bool is_in(int r, int c){
  31. return r >= 0 && r < n && c >= 0 && c < m;
  32. }
  33. inline LL Max(LL a, LL b){ return a < b ? b : a; }
  34. inline LL Min(LL a, LL b){ return a > b ? b : a; }
  35. int a[maxn];
  36.  
  37. int main(){
  38. while(scanf("%d", &n) == 1){
  39. for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
  40. sort(a, a+n);
  41. scanf("%d", &m);
  42. while(m--){
  43. int x;
  44. scanf("%d", &x);
  45. printf("%d\n", upper_bound(a, a+n, x) - a);
  46. }
  47. }
  48. return 0;
  49. }

CodeForces 706B Interesting drink (二分查找)的更多相关文章

  1. Codeforces - 706B - Interesting drink - 二分 - 简单dp

    https://codeforces.com/problemset/problem/706/B 因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $ ...

  2. CodeForces - 706B Interesting drink(二分查找)

    Interesting drink Problem Vasiliy likes to rest after a hard work, so you may often meet him in some ...

  3. 【二分】Codeforces 706B Interesting drink

    题目链接: http://codeforces.com/problemset/problem/706/B 题目大意: n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m ...

  4. CodeForces 706B Interesting drink

    排序,二分. 将$x$数组从小到大排序,每次询问的时候只要二分一下位置就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000& ...

  5. codeforces 706B B. Interesting drink(二分)

    题目链接: B. Interesting drink 题意: 给出第i个商店的价钱为x[i],现在询问mi能在多少个地方买酒; 思路: sort后再二分; AC代码: #include <ios ...

  6. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  7. CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)

    传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...

  8. 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

    题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...

  9. Codeforces 475D 题解(二分查找+ST表)

    题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...

随机推荐

  1. 418. Sentence Screen Fitting

    首先想到的是直接做,然后TLE. public class Solution { public int wordsTyping(String[] sentence, int rows, int col ...

  2. uva1639 Candy

    组合数,对数. 这道题要用到20w的组合数,如果直接相乘的话,会丢失很多精度,所以用去对数的方式实现. 注意指数,因为取完一次后,还要再取一次才能发现取完,所以是(n+1)次方. double 会爆掉 ...

  3. UVa 580 (递推) Critical Mass

    题意: 有两种盒子分别装有铀(U)和铅(L),现在把n个盒子排成一列(两种盒子均足够多),而且要求至少有3个铀放在一起,问有多少种排放方法. 分析: n个盒子排成一列,共有2n中方案,设其中符合要求的 ...

  4. apache开源项目-- Usergrid

    Ed Anuff上周宣布第一版 Usergrid 的代码已经发布,Usergrid 是一款适用于移动和富客户端应用的综合性平台.Ed 认为,良好的移动性指的是将设备中运行应用的良好交互带到云中,其中既 ...

  5. 计算时间间隔的js

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. OracleBulkCopy的批量数据导入

    private void button1_Click(object sender, EventArgs e) { OpenFileDialog afd = new OpenFileDialog(); ...

  7. 关于DatePicker控件在IsEnabled为False视觉效果没有明显辨识度的处理方法

    DatePicker控件在IsEnabled为False时界面没有让人看上去不可用(背景为灰色等)的效果.容易让用户迷惑. 可以用下面的代码增加设置透明度的触发器来解决(XAML以及C#方式): &l ...

  8. C#发送Email邮件(实例:QQ邮箱和Gmail邮箱)

    下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用: using System.Net.Mail; using System.Text; using System.Net; ...

  9. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(3)

    运行ElasticSearch(Running ElasticSearch) 让我们运行我们的第一个实例.转到bin目录并从命令行运行以下命令: ./elasticsearch –f (Linux o ...

  10. HDU5739 Fantasia 树形dp + 点双缩点

    这个题当时打多校的时候有思路,但是代码能力差,没有写出来 事后看zimpha巨巨的题解,看了觉得基本差不多 核心思路:就是找出割点,然后变成森林,然后树形dp就可以搞了 关键就在重新构图上,缩完点以后 ...