CodeForces 706B Interesting drink (二分查找)
题意:给定 n 个数,然后有 m 个询问,每个询问一个数,问你小于等于这个数的数有多少个。
析:其实很简单么,先排序,然后十分查找,so easy。
代码如下:
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <iostream>
- #include <cstring>
- #include <set>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <cctype>
- #include <stack>
- using namespace std;
- typedef long long LL;
- typedef pair<int, int> P;
- const int INF = 0x3f3f3f3f;
- const double inf = 0x3f3f3f3f3f3f;
- const LL LNF = 100000000000000000;
- const double PI = acos(-1.0);
- const double eps = 1e-8;
- const int maxn = 1e5 + 5;
- const int mod = 1e9 + 7;
- const char *mark = "+-*";
- const int dr[] = {-1, 0, 1, 0};
- const int dc[] = {0, 1, 0, -1};
- int n, m;
- inline bool is_in(int r, int c){
- return r >= 0 && r < n && c >= 0 && c < m;
- }
- inline LL Max(LL a, LL b){ return a < b ? b : a; }
- inline LL Min(LL a, LL b){ return a > b ? b : a; }
- int a[maxn];
- int main(){
- while(scanf("%d", &n) == 1){
- for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
- sort(a, a+n);
- scanf("%d", &m);
- while(m--){
- int x;
- scanf("%d", &x);
- printf("%d\n", upper_bound(a, a+n, x) - a);
- }
- }
- return 0;
- }
CodeForces 706B Interesting drink (二分查找)的更多相关文章
- Codeforces - 706B - Interesting drink - 二分 - 简单dp
https://codeforces.com/problemset/problem/706/B 因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $ ...
- 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
排序,二分. 将$x$数组从小到大排序,每次询问的时候只要二分一下位置就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000& ...
- 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 - 600B Queries about less or equal elements (二分查找 利用stl)
传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- Codeforces 475D 题解(二分查找+ST表)
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...
随机推荐
- 418. Sentence Screen Fitting
首先想到的是直接做,然后TLE. public class Solution { public int wordsTyping(String[] sentence, int rows, int col ...
- uva1639 Candy
组合数,对数. 这道题要用到20w的组合数,如果直接相乘的话,会丢失很多精度,所以用去对数的方式实现. 注意指数,因为取完一次后,还要再取一次才能发现取完,所以是(n+1)次方. double 会爆掉 ...
- UVa 580 (递推) Critical Mass
题意: 有两种盒子分别装有铀(U)和铅(L),现在把n个盒子排成一列(两种盒子均足够多),而且要求至少有3个铀放在一起,问有多少种排放方法. 分析: n个盒子排成一列,共有2n中方案,设其中符合要求的 ...
- apache开源项目-- Usergrid
Ed Anuff上周宣布第一版 Usergrid 的代码已经发布,Usergrid 是一款适用于移动和富客户端应用的综合性平台.Ed 认为,良好的移动性指的是将设备中运行应用的良好交互带到云中,其中既 ...
- 计算时间间隔的js
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- OracleBulkCopy的批量数据导入
private void button1_Click(object sender, EventArgs e) { OpenFileDialog afd = new OpenFileDialog(); ...
- 关于DatePicker控件在IsEnabled为False视觉效果没有明显辨识度的处理方法
DatePicker控件在IsEnabled为False时界面没有让人看上去不可用(背景为灰色等)的效果.容易让用户迷惑. 可以用下面的代码增加设置透明度的触发器来解决(XAML以及C#方式): &l ...
- C#发送Email邮件(实例:QQ邮箱和Gmail邮箱)
下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用: using System.Net.Mail; using System.Text; using System.Net; ...
- 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(3)
运行ElasticSearch(Running ElasticSearch) 让我们运行我们的第一个实例.转到bin目录并从命令行运行以下命令: ./elasticsearch –f (Linux o ...
- HDU5739 Fantasia 树形dp + 点双缩点
这个题当时打多校的时候有思路,但是代码能力差,没有写出来 事后看zimpha巨巨的题解,看了觉得基本差不多 核心思路:就是找出割点,然后变成森林,然后树形dp就可以搞了 关键就在重新构图上,缩完点以后 ...