题目链接:

  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 ;
}
/*
// //
*/

最新文章

  1. &quot;Installation failed !&quot; in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated )
  2. Hibernate的面试题
  3. WPF系列:样式
  4. Unity3D Animation Curve
  5. WinSCP 连接 Ubuntu 拒绝的问题
  6. C#常用方法集合
  7. ubuntu install wine
  8. HEX格式数据转换成十六进制字符串
  9. Oracle sql trace
  10. android上的缓存、缓存算法和缓存框架
  11. Tomcat内存溢出详解【转载】
  12. web项目启动,运行方法
  13. 不同版本的mysql字符集的默认编写
  14. 用js,css3 做的一个球
  15. 写给小白的JAVA链接MySQL数据库的步骤(JDBC):
  16. C# 枚举使用和对应说明获取实例
  17. Stanford Local 2016 G &quot;Ground Defense&quot;(线段树)
  18. java集合框架-List集合ArrayList和LinkedList详解
  19. 全网最详细的Windows系统里PLSQL Developer 64bit的下载与安装过程(图文详解)
  20. 消息中间件 ActiveMQ的简单使用

热门文章

  1. PHP 函数的“引用返回”概念释疑(转)
  2. Understanding Extension Class Loading--官方
  3. iOS开发系列之远程控制事件
  4. Java基础知识强化之IO流笔记16:IO流的概述和分类
  5. yii自动登陆的验证机制浅析
  6. codevs 1281 Xn数列 (矩阵乘法)
  7. C#学习第二天
  8. Windows上帝模式
  9. CoreLocation+MapKit系统定位(含坐标以及详细地址)
  10. Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell&#39;s content view...