题目链接:

  http://codeforces.com/problemset/problem/706/B

题目大意

  n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m(1≤m≤100 000)天,每天有Cj的钱,问每天可以负的起的商店数。

题目思路:

  【二分】

  排个序,二分。

  1. //
  2. //by coolxxx
  3. //
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<string>
  7. #include<iomanip>
  8. #include<memory.h>
  9. #include<time.h>
  10. #include<stdio.h>
  11. #include<stdlib.h>
  12. #include<string.h>
  13. //#include<stdbool.h>
  14. #include<math.h>
  15. #define min(a,b) ((a)<(b)?(a):(b))
  16. #define max(a,b) ((a)>(b)?(a):(b))
  17. #define abs(a) ((a)>0?(a):(-(a)))
  18. #define lowbit(a) (a&(-a))
  19. #define sqr(a) ((a)*(a))
  20. #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
  21. #define eps (1e-8)
  22. #define J 10000000
  23. #define MAX 0x7f7f7f7f
  24. #define PI 3.1415926535897
  25. #define N 100004
  26. using namespace std;
  27. typedef long long LL;
  28. int cas,cass;
  29. int n,m,lll,ans;
  30. int a[N];
  31. bool cmp(int aa,int bb)
  32. {
  33. return aa<bb;
  34. }
  35. int work(int v)
  36. {
  37. int l=,r=n,mid;
  38. while(l<r)
  39. {
  40. mid=(l+r+)>>;
  41. if(v>=a[mid])l=mid;
  42. else r=mid-;
  43. }
  44. return r;
  45. }
  46. int main()
  47. {
  48. #ifndef ONLINE_JUDGE
  49. // freopen("1.txt","r",stdin);
  50. // freopen("2.txt","w",stdout);
  51. #endif
  52. int i,j,x,v;
  53. // for(scanf("%d",&cas);cas;cas--)
  54. // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
  55. // while(~scanf("%s",s))
  56. while(~scanf("%d",&n))
  57. {
  58. for(i=,x=;i<=n;i++)
  59. {
  60. scanf("%d",&a[i]);
  61. x=max(a[i],x);
  62. }
  63. sort(a+,a++n,cmp);
  64. scanf("%d",&m);
  65. for(i=;i<=m;i++)
  66. {
  67. scanf("%d",&v);
  68. if(v>=x)printf("%d\n",n);
  69. else printf("%d\n",work(v));
  70. }
  71. }
  72. return ;
  73. }
  74. /*
  75. //
  76.  
  77. //
  78. */

【二分】Codeforces 706B Interesting drink的更多相关文章

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

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

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

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

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

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

  4. CodeForces 706B Interesting drink

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

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

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

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

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

  7. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  8. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  9. CodeForces - 706B 二分stl

    #include<iostream> #include<cstdio> #include<cstring> #include<string> #incl ...

随机推荐

  1. cocos2d-x项目过程记录(ios和android设备的适配)

    (原创作品,欢迎转载,注明出处,谢谢:http://www.cnblogs.com/binxindoudou/admin/EditPosts.aspx?postid=3213645) 1.原理分析的博 ...

  2. 使用APICloud设计物联网APP

    0.前言 1).APP功能: 1.控制室内插座的开关. 2.查看室内实时温湿度和温湿度趋势. 3.控制小车的行走,小车摄像头的开启/关闭.移动. 4.查看摄像头监控画面,可拍照并追溯. 5.查看服务器 ...

  3. SSH常用命令选项

    SSH 是什么 SSH(全称 Secure Shell)是一种加密的网络协议.使用该协议的数据将被加密,如果在传输中间数据泄漏,也可以确保没有人能读取出有用信息.要使用 SSH,目标机器应该安装 SS ...

  4. dedecms调用所有顶级栏目最新文章的实现方法

    做dedecms的模板,我们会遇到各种各样的调用问题,dedecms列表页调用所有顶级栏目文章列表的方法如下所述: 在文章页面经常使用的是 {dede:arclist orderby='pubdate ...

  5. linux 'more' command.

    more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...

  6. AutoLayout适配

    http://www.raywenderlich.com/113768/adaptive-layout-tutorial-in-ios-9-getting-started iOS布局和屏幕适配的一点总 ...

  7. iPhone真机测试Crash信息分析

    一.获取Crash Log的方式 在iOS开发过程,当应用已经打包,iPhone设备通过ipa的包安装应用后,在使用过程发现crash,那么如何获取crash日志呢,现提供如下四种获取crash日志的 ...

  8. IIS网站部署错误总结

    aspx 常见错误 CS0016: 未能写入输出文件“c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/... ...

  9. ERROR:the server has either erred or is incapable of performing the requested operation

    openstack中,有时会经常出现这种错误,原因无二,一是安全组没有设置正确,二是openstack中网络配置会有些问题或者是相关的服务没有启动. 解决方法:1.安全组问题在nova.conf和ne ...

  10. mysql报Fatal error encountered during command execution的解决办法

    连接字符串里加上 Allow User Variables=True 解决. 否则时不时的报错,存储过程名长一点也报错,又有时报有时不报,参数传1位数就正常2位数就报错等…… 折腾mysql蛋疼啊