B. Interesting drink
链接
[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的更多相关文章
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- codeforces 706B B. Interesting drink(二分)
题目链接: B. Interesting drink 题意: 给出第i个商店的价钱为x[i],现在询问mi能在多少个地方买酒; 思路: sort后再二分; AC代码: #include <ios ...
- 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 (二分查找)
题意:给定 n 个数,然后有 m 个询问,每个询问一个数,问你小于等于这个数的数有多少个. 析:其实很简单么,先排序,然后十分查找,so easy. 代码如下: #pragma comment(lin ...
- 【二分】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 - Interesting drink - 二分 - 简单dp
https://codeforces.com/problemset/problem/706/B 因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $ ...
- Codeforces Round #367 (Div. 2)
A题 Beru-taxi 随便搞搞.. #include <cstdio> #include <cmath> using namespace std; int a,b,n; s ...
- CF 706B 简单二分,水
1.CF 706B Interesting drink 2.链接:http://codeforces.com/problemset/problem/706/B 3.总结:二分 题意:给出n个数,再给 ...
随机推荐
- VsCode 的使用
一.简介 VsCode(Visual Studio Code),官网地址:https://code.visualstudio.com/ Visual Studio Code is a lightwei ...
- Qt实现同步(阻塞式)http get等网络访问操作
Qt的网络操作类是异步(非阻塞的),但有时想做一些阻塞的事情就不方便了,可用如下几行代码轻松实现: QByteArray MyNetworkAccess::get(const QString & ...
- 【转】handbrake使用教程
原文地址http://tieba.baidu.com/p/2399590151?pn=1 现在的很多压制教程基本都是使用megui或者mediacoder的,这两个软件使 ...
- Python3编写网络爬虫08-数据存储方式一-文件存储
数据存储 用解析器解析出数据之后,就是存储数据了.保存的形式可以多种多样,最简单的形式是直接保存为文本文件,如TXT JSON CSV等.另外还可以保存到数据库中,如关系型数据库MySQL 非关系型数 ...
- pb中遍历查询数据库数据问题(数据库为 sql server)
指针可以实现但是不推荐 例如:(部分代码) for ll_a = 1 to ll_count ll_b = ll_i + ll_a //插入行行号先下移一位 dw_main.inser ...
- github拓展,以及ModelForm的使用
github - git init/add/commit/reset/log/status/stash pop/checkout/branch 新入职到公司,地址: git clone h ...
- Spring 注解大全
@Autowired 自动注入 (存在多个可注入Bean时,通过 @Qualifier 指定)@Resource 与@Autowired作用相同@Repository 只能标注在 DAO 类上.该注解 ...
- margin auto 实现居中,与text-align:center的区别
本文导读:一个元素在水平方向上所占的长度,由width ,padding ,和margin 决定.这些值中,只有width和margin-left,margin-right可以设为auto,text- ...
- Linux系统学习之进程管理
什么是进程? 进程表示程序的一次执行过程,它是应用程序的运行实例,是一个动态的过程.或者可以更简单地描述为:进程是操作系统当前运行的程序.当一个进程开始运行时,就要启动了这个过程.进程包括动态的执行的 ...
- 【Atcoder yahoo-procon2019-qual D】 Ears
Atcoder yahoo-procon2019-qual D 题意:给你\(L\)个耳朵(???),以及一条范围从\(0\)到\(L\)的数轴,你可以选择一个出发点,从该点开始随意走动,如果经过了\ ...