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

因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $10^6$ ,可以用复杂度为 $O(max(x_i))$ 的dp去做。

也就是说,当这道题的可乐数量上升,二分就容易超时,而可乐的价格上升则dp容易爆内存且超时。各有所长

#include<bits/stdc++.h>
using namespace std;
#define ll long long int a[]; struct day{
int idx;
int coin;
int cnt;
day(int idx=,int coin=):idx(idx),coin(coin){}
}d[]; struct cmp{
bool operator()(day &d1,day &d2){
return d1.coin<d2.coin;
}
}; struct cmp2{
bool operator()(day &d1,day &d2){
return d1.idx<d2.idx;
}
}; int dp[]; int main(){
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n); int q;
scanf("%d",&q);
for(int i=;i<q;i++){
scanf("%d",&d[i].coin);
d[i].idx=i;
}
sort(d,d+q,cmp()); //d[0].cnt=upper_bound(a,a+n,d[0].coin)-a;
for(int i=;i<q;i++){
d[i].cnt=upper_bound(a,a+n,d[i].coin)-a;
//d[i].idx=i;
} sort(d,d+q,cmp2()); for(int i=;i<q;i++){
printf("%d\n",d[i].cnt);
//d[i].idx=i;
}
}

2019-01-16

Codeforces - 706B - Interesting drink - 二分 - 简单dp的更多相关文章

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

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

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

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

  3. 【二分】Codeforces 706B Interesting drink

    题目链接: http://codeforces.com/problemset/problem/706/B 题目大意: n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m ...

  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 627D Preorder Test(二分+树形DP)

    题意:给出一棵无根树,每个节点有一个权值,现在要让dfs序的前k个结点的最小值最大,求出这个值. 考虑二分答案,把>=答案的点标记为1,<答案的点标记为0,现在的任务时使得dfs序的前k个 ...

  7. Codeforces - 773A - Success Rate - 二分 - 简单数论

    https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...

  8. codeforces 710E Generate a String(简单dp)

    传送门:http://codeforces.com/problemset/problem/710/E 分析: 让你写一个全由"a"组成的长为n的串,告诉你两种操作,第一种:插入一个 ...

  9. Codeforces - 9D - How many trees? - 简单dp - 组合数学

    https://codeforces.com/problemset/problem/9/D 一开始居然还想直接找公式的,想了想还是放弃了.原来这种结构是要动态规划. 状态是知道怎么设了,$t_{nh} ...

随机推荐

  1. 使用nginx转发不了静态文件

    从django runserver的请求来看,都收不到静态文件请求, 查看firefox的web console请求,发现都是403 然后发现nginx不在当前用户组,并且当前用户的项目的读写权限是7 ...

  2. android官方Api 理解Activity生命周期的回调机制(适合有基础的人看)

    原文地址:http://www.android-doc.com/training/basics/activity-lifecycle/starting.html#lifecycle-states 此处 ...

  3. Redhat7/centOs7 安装配置python3.6.5

    centos默认安装python2,设置py2和py3并存的方法如下: sudo yum install openssl-devel -y sudo yum install zlib-devel -y ...

  4. [原创]安装Ubuntu Server 14.04后

    安装后许多软件都没有,需要进行安装. 官方指南:https://help.ubuntu.com/lts/serverguide/index.html 1.修改网络配置文件 用ifconfig查看本地网 ...

  5. 下篇:express、koa1、koa2的中间件原理

    本作品采用知识共享署名 4.0 国际许可协议进行许可.转载联系作者并保留声明头部与原文链接https://luzeshu.com/blog/express-koa 本博客同步在http://www.c ...

  6. HDU oj 开门人与关门人

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1234 #include<stdio.h> #include<string.h> ...

  7. 【转载】一张“神图”看懂单机/集群/热备/磁盘阵列(RAID)

    单机部署(stand-alone):只有一个饮水机提供服务,服务只部署一份 集群部署(cluster):有多个饮水机同时提供服务,服务冗余部署,每个冗余的服务都对外提供服务,一个服务挂掉时依然可用 热 ...

  8. glGenLists返回0或None的原因

    最近调用PyOpenGL做显示,想在程序启动时候调用Display List进行显示,但是glGenLists返回None,若在程序启动后调用则没有任何问题. 搜索谷歌后,给出的解释: This ca ...

  9. andfix使用

    1.andfix简介 AndFix是一个Android App的在线热补丁框架.使用此框架,我们能够在不重复发版的情况下,在线修改App中的Bug.AndFix就是 “Android Hot-Fix” ...

  10. install build tools 25.0.2 and sync the project

    install build tools 25.0.2 and sync the project in android studio bundle.gradle,将buildToolsVersion修改 ...