codeforces 706B B. Interesting drink(二分)
题目链接:
题意:
给出第i个商店的价钱为x[i],现在询问mi能在多少个地方买酒;
思路:
sort后再二分;
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <bits/stdc++.h>
using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=998244353;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e5+10;
const int maxn=1e3+10;
const double eps=1e-4; int n,a[N];
int main()
{
read(n);
For(i,1,n)read(a[i]);
sort(a+1,a+n+1);
int q,m;
read(q);
while(q--)
{
read(m);
int l=1,r=n;
while(l<=r)
{
int mid=(l+r)>>1;
if(a[mid]<=m)l=mid+1;
else r=mid-1;
}
printf("%d\n",l-1);
}
return 0;
}
codeforces 706B B. Interesting drink(二分)的更多相关文章
- 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(二分查找)
Interesting drink Problem Vasiliy likes to rest after a hard work, so you may often meet him in some ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- 【二分】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 二分stl
#include<iostream> #include<cstdio> #include<cstring> #include<string> #incl ...
- CodeForces 377B---Preparing for the Contest(二分+贪心)
C - Preparing for the Contest Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- Codeforces 484B Maximum Value(高效+二分)
题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...
随机推荐
- List集合的遍历方法
估计你永远都不会忘记这三个方法了...... public static void main(String[] args) { //超级for循环遍历方法 List<String> lis ...
- Codeforces Round #263 (Div. 2) proB
题目: B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input ...
- Chrome + Python 抓取动态网页内容
用Python实现常规的静态网页抓取时,往往是用urllib2来获取整个HTML页面,然后从HTML文件中逐字查找对应的关键字.如下所示: import urllib2 url="http: ...
- Java线程:概念及原理
线程是执行的程序中的一个线程. Java虚拟机允许应用程序必须同时运行多个执行线程. 每个线程都有一个优先事项.具有更高优先级的线程优先于线程的优先级较低的执行.每个线程可能会或可能不会也被标记为一个 ...
- 短信计时器Utils
package com.lvshandian.partylive.utils; import android.content.Context;import android.os.CountDownTi ...
- 可展开的UITableView (附源码)
本文转载至 http://www.apkbus.com/forum.php?mod=viewthread&tid=137207&extra=page%3D1 由于工作需要,写了一个UI ...
- python 基础 2.4 while 循环
#/usr/bin/python #coding=utf-8 #@Time :2017/10/18 15:31 #@Auther :liuzhenchuan #@File :while 循环.py 示 ...
- matlab实战中一些重要的函数总结
这段时间看了一些大型的matlabproject文件(如:faster r-cnn),对于project中常常要用到的一些函数进行一个总结. 1.路径问题. 这主要涵括文件路径的包括和组合. curd ...
- git版本控制-- Windows+Git+TortoiseGit+COPSSH安装图文教程
Windows+Git+TortoiseGit+COPSSH 安装图文教程 教程网址: http://www.liaoxuefeng.com/wiki/0013739516305929606dd183 ...
- [容易]Fizz Buzz 问题
题目来源:http://www.lintcode.com/zh-cn/problem/fizz-buzz/