链接

[http://codeforces.com/group/1EzrFFyOc0/contest/706/problem/B]

题意

给你n个数,q次查询,每次输入一个m,问n个数中有多少个数小于等于m

思路

先排序,再用upper_bound找,该函数返回第一个大于m的下标。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("in.txt","r",stdin);
int n,a[100005];
int q,i,m;
while(cin>>n){
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
cin>>q;
for(i=0;i<q;i++)
{
cin>>m;
int ans = upper_bound(a, a+n, m) - a;
printf("%d\n", ans);
}
}
return 0;
}

B. Interesting drink的更多相关文章

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

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

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

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

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

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

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

    题意:给定 n 个数,然后有 m 个询问,每个询问一个数,问你小于等于这个数的数有多少个. 析:其实很简单么,先排序,然后十分查找,so easy. 代码如下: #pragma comment(lin ...

  5. 【二分】Codeforces 706B Interesting drink

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

  6. CodeForces 706B Interesting drink

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

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

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

  8. Codeforces Round #367 (Div. 2)

    A题 Beru-taxi 随便搞搞.. #include <cstdio> #include <cmath> using namespace std; int a,b,n; s ...

  9. CF 706B 简单二分,水

    1.CF 706B  Interesting drink 2.链接:http://codeforces.com/problemset/problem/706/B 3.总结:二分 题意:给出n个数,再给 ...

随机推荐

  1. JavaScript 中的匿名函数((function() {})();)与变量的作用域

    以前都是直接用前端框架Bootstrap,突然想看看Javascript,发现javascript是个非常有趣的东西,这里把刚碰到的一个小问题的理解做下笔录(废话不多说,上代码). /** * Exa ...

  2. 第一条:了解Objective-C语言的起源

    第一条:了解Objective-C语言的起源 Objective-C使用的消息结构而非函数调用. Objective-C的重要工作都由"运行组件(runtime component)&quo ...

  3. 删除排序数组中的重复项的golang实现

    给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成. 给定数组 ...

  4. 基于tomcat插件的maven多模块工程热部署(附插件源码)

    内容属原创,转载请注明出处 写在前面的话 最近一直比较纠结,归根结底在于工程的模块化拆分.以前也干过这事,但是一直对以前的结果不满意,这会重操旧业,希望搞出个自己满意的结果. 之前有什么不满意的呢? ...

  5. python第五十一课——__slots

    2.__slots__: 作用:限制对象随意的动态添加属性 举例: class Demo: __slots__ = ('name','age','height','weight') #实例化Demo对 ...

  6. API--ResponseBody-类

    import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInc ...

  7. JDK文档中关于Semaphore的正确使用以及使用场景

    import java.util.concurrent.Semaphore; /** * * JDK文档使用备注:<br> * Semaphores are often used to r ...

  8. jQuery 自定义函数写法分享

    时间:02月20日   自定义主要通过两种方式实现$.extend({aa:function(){}});$.fn.extend({aa:function(){}});调用的方法分别是:$.aa(); ...

  9. 蒟蒻qxt的sd'日常

    emm... 今天刷了一道水题 居然 死循环了 真的是水题啊 顿时自闭 (救救孩子吧) 结果 bug是 我把for循环中的i的值改变了 使得i的值一直都不会达到他的边界值 于是就死循环了 所以 要用到 ...

  10. PAT A1024 Palindromic Number (25 分)——回文,大整数

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...