CodeForces 706B Interesting drink
排序,二分。
将$x$数组从小到大排序,每次询问的时候只要二分一下位置就可以了。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} const int maxn=;
int n,q,x[maxn]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&x[i]);
sort(x+,x++n);
scanf("%d",&q);
for(int i=;i<=q;i++)
{
int p; scanf("%d",&p);
int L=,R=n,pos=-;
while(L<=R)
{
int mid=(L+R)/;
if(x[mid]<=p) pos=mid,L=mid+;
else R=mid-;
}
if(pos==-) printf("%d\n",);
else printf("%d\n",pos);
}
return ;
}
CodeForces 706B Interesting drink的更多相关文章
- 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
题目链接: http://codeforces.com/problemset/problem/706/B 题目大意: n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m ...
- Codeforces - 706B - Interesting drink - 二分 - 简单dp
https://codeforces.com/problemset/problem/706/B 因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $ ...
- CodeForces 706B Interesting drink (二分查找)
题意:给定 n 个数,然后有 m 个询问,每个询问一个数,问你小于等于这个数的数有多少个. 析:其实很简单么,先排序,然后十分查找,so easy. 代码如下: #pragma comment(lin ...
- codeforces 706B B. Interesting drink(二分)
题目链接: B. Interesting drink 题意: 给出第i个商店的价钱为x[i],现在询问mi能在多少个地方买酒; 思路: sort后再二分; AC代码: #include <ios ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces 482B Interesting Array(线段树)
题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...
- codeforces 482B. Interesting Array【线段树区间更新】
题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...
- B. Interesting drink
链接 [http://codeforces.com/group/1EzrFFyOc0/contest/706/problem/B] 题意 给你n个数,q次查询,每次输入一个m,问n个数中有多少个数小于 ...
随机推荐
- XLSTransformer生成excel文件
jxls的使用方法: 1)声明一个XLSTransformer对象,生成方式就是使用new操作符 XLSTransformer transformer = new XL ...
- Play 起步
*****************jdk下载地址: http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.ta ...
- speedbar , tabbar 还有linum-mode
我的Emacs折腾经验谈(三) speedbar , tabbar 还有linum-mode 离上一篇博客已经很遥远了,最近总是各种逛,但没有心思静下来写点东西,这回写一下我之前用的一些东西. Spe ...
- 我的Emacs折腾经验谈(四) 也谈Yasnippet
又是好久没更新了,不过还好,现在慢慢有点感觉了,好长时间不写博客会心里有点感觉欠一点什么东西.觉得每次写了东西都往主页推搞得压力好大,以后就不往网站首页推了,纯留下来供参考,另外就是主要方便从搜索找过 ...
- 编写类String 的构造函数、析构函数和赋值函数
编写类String 的构造函数.析构函数和赋值函数,已知类String 的原型为:class String{public:String(const char *str = NULL); // 普通构造 ...
- Linux 学习 step by step (2)
Linux 学习 step by step (2) Linux,想要我说爱你真的不容易了,尽管,你是ubutun,尽管,你有蛮界面.但是,操作你,还是没有操作windows那么的如鱼得水了.为了更 ...
- 内容中断随想录(risc cpu的那些事)
发一下牢骚和主题无关: [ 声明:版权所有,欢送转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 从消费电子的soc芯片来讲,当初海内从事芯片设计的企业还是很多的,这其 ...
- CSS3高级
一.学习目标 二.box-sizing属性 语法:box-sizing: content-box|border-box|inherit box-sizing属性的用法: box-sizing属性可以为 ...
- MS Word 目录排版
昨天整理一份把网页的内容复制粘贴到Word里的文件,碰到了这样一个问题: 网页上面也会有一级标题,二级标题,三级标题等.当我们在写博客的时候,也会去使用这些.这也就导致复制过来之后,直接生成的目录很乱 ...
- Andy的生活
Andy是一个善良的男孩,希望优雅地生活. 现实是残酷的. 现实是,Andy像狗一样活着. Andy犯的错是,错误地认为狗一样的生活将在高考结束的那一刻结束. 大学四年时间根本没有静下心来学习,却在生 ...