题目链接:

  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的更多相关文章

  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. Android Studio学习随笔-基本事件(点击)

    最常见的点击事件有三种创建方法,在MainActivity.java的onCreate函数(在启动程序是优先运行的程序)中创建setOnClickListener(动态运行)(最常见) protect ...

  2. 有意思的字符串反转(JavaScript)

    有意思的字符串反转 如果问你,实现对一串字符串进行反转操作,你的第一反应的方法是? 第一个我想到的是,利用Array.Reverse来实现: var test = 'Skylor.min'; test ...

  3. js求字符长度

    </script> <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  4. (转)PHP函数之error_reporting(E_ALL ^ E_NOTICE)详细说明

    在看帝国cms的connect.php是发现第一句是error_reporting(E_ALL ^ E_NOTICE);以前也没注意过这个语句,知道是设置错误提示的,但不清楚具体怎样设置使用.下面从网 ...

  5. java获取对象属性类型、属性名称、属性值 【转】

    /** * 根据属性名获取属性值 * */ private Object getFieldValueByName(String fieldName, Object o) { try { String ...

  6. javascript之typeof、constructor、instanceof

    ref: http://jingyan.baidu.com/article/29697b912f9939ab20de3c8c.html

  7. 34.Spring-Aop.md

    http://blog.csdn.net/bigtree_3721/article/details/50759843 目录 [toc] --- 1.概念 1.1概念 AOP是Spring提供的关键特性 ...

  8. C++ nullptr 的一种实现

    C/C++ 程序员都应该了解NULL, 0, nullptr,  NULL表示空指针,即指针不指向任何对象,C++11后有多了nullptr更好是表了这类概念,看看nullptr是如何实现的: con ...

  9. 『重构--改善既有代码的设计』读书笔记----Remove Assignments to Parameters

    C++存在按值传递和按引用传递两种传递方式,Java严格按照按值传递这种方式来进行.以按值传递方式的角度来说,如果你 int test(int a) { ) { a = 1; } return a; ...

  10. Cookie、LocalStorge、SesstionStorge 的区别和用法

    前言 总括:详细讲述Cookie.LocalStorge.SesstionStorge的区别和用法. 1. 各种存储方案的简单对比 Cookies:浏览器均支持,容量为4KB UserData:仅IE ...