【二分】Codeforces 706B Interesting drink
题目链接:
http://codeforces.com/problemset/problem/706/B
题目大意:
n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m(1≤m≤100 000)天,每天有Cj的钱,问每天可以负的起的商店数。
题目思路:
【二分】
排个序,二分。
- //
- //by coolxxx
- //
- #include<iostream>
- #include<algorithm>
- #include<string>
- #include<iomanip>
- #include<memory.h>
- #include<time.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- //#include<stdbool.h>
- #include<math.h>
- #define min(a,b) ((a)<(b)?(a):(b))
- #define max(a,b) ((a)>(b)?(a):(b))
- #define abs(a) ((a)>0?(a):(-(a)))
- #define lowbit(a) (a&(-a))
- #define sqr(a) ((a)*(a))
- #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
- #define eps (1e-8)
- #define J 10000000
- #define MAX 0x7f7f7f7f
- #define PI 3.1415926535897
- #define N 100004
- using namespace std;
- typedef long long LL;
- int cas,cass;
- int n,m,lll,ans;
- int a[N];
- bool cmp(int aa,int bb)
- {
- return aa<bb;
- }
- int work(int v)
- {
- int l=,r=n,mid;
- while(l<r)
- {
- mid=(l+r+)>>;
- if(v>=a[mid])l=mid;
- else r=mid-;
- }
- return r;
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- // freopen("1.txt","r",stdin);
- // freopen("2.txt","w",stdout);
- #endif
- int i,j,x,v;
- // for(scanf("%d",&cas);cas;cas--)
- // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
- // while(~scanf("%s",s))
- while(~scanf("%d",&n))
- {
- for(i=,x=;i<=n;i++)
- {
- scanf("%d",&a[i]);
- x=max(a[i],x);
- }
- sort(a+,a++n,cmp);
- scanf("%d",&m);
- for(i=;i<=m;i++)
- {
- scanf("%d",&v);
- if(v>=x)printf("%d\n",n);
- else printf("%d\n",work(v));
- }
- }
- 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 - 二分 - 简单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 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 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,最后问你原来的数 ...
- CodeForces - 706B 二分stl
#include<iostream> #include<cstdio> #include<cstring> #include<string> #incl ...
随机推荐
- cocos2d-x项目过程记录(ios和android设备的适配)
(原创作品,欢迎转载,注明出处,谢谢:http://www.cnblogs.com/binxindoudou/admin/EditPosts.aspx?postid=3213645) 1.原理分析的博 ...
- 使用APICloud设计物联网APP
0.前言 1).APP功能: 1.控制室内插座的开关. 2.查看室内实时温湿度和温湿度趋势. 3.控制小车的行走,小车摄像头的开启/关闭.移动. 4.查看摄像头监控画面,可拍照并追溯. 5.查看服务器 ...
- SSH常用命令选项
SSH 是什么 SSH(全称 Secure Shell)是一种加密的网络协议.使用该协议的数据将被加密,如果在传输中间数据泄漏,也可以确保没有人能读取出有用信息.要使用 SSH,目标机器应该安装 SS ...
- dedecms调用所有顶级栏目最新文章的实现方法
做dedecms的模板,我们会遇到各种各样的调用问题,dedecms列表页调用所有顶级栏目文章列表的方法如下所述: 在文章页面经常使用的是 {dede:arclist orderby='pubdate ...
- linux 'more' command.
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...
- AutoLayout适配
http://www.raywenderlich.com/113768/adaptive-layout-tutorial-in-ios-9-getting-started iOS布局和屏幕适配的一点总 ...
- iPhone真机测试Crash信息分析
一.获取Crash Log的方式 在iOS开发过程,当应用已经打包,iPhone设备通过ipa的包安装应用后,在使用过程发现crash,那么如何获取crash日志呢,现提供如下四种获取crash日志的 ...
- IIS网站部署错误总结
aspx 常见错误 CS0016: 未能写入输出文件“c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/... ...
- ERROR:the server has either erred or is incapable of performing the requested operation
openstack中,有时会经常出现这种错误,原因无二,一是安全组没有设置正确,二是openstack中网络配置会有些问题或者是相关的服务没有启动. 解决方法:1.安全组问题在nova.conf和ne ...
- mysql报Fatal error encountered during command execution的解决办法
连接字符串里加上 Allow User Variables=True 解决. 否则时不时的报错,存储过程名长一点也报错,又有时报有时不报,参数传1位数就正常2位数就报错等…… 折腾mysql蛋疼啊