Contest Balloons

题目链接:http://codeforces.com/problemset/problem/725/D

贪心+枚举

每次在排名在自己前面的选出w-t值最小的送气球,更新rank即可。

(一直觉得cin比scanf不会慢太多,结果我跑出来是2000ms,队友300ms...)

代码如下:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define Min(x,y) (x<y?x:y)
#define N 300005
using namespace std;
typedef long long LL;
LL n,k,t,w,rk,ans,index;
struct nod{
LL t,w,diff;
nod(LL tt=,LL ww=){
t=tt,w=ww;
diff=w-t;
}
bool operator < (const nod &b)const{
return diff>b.diff;
}
}a[N];
bool cmp(nod a,nod b){
return a.t>b.t;
}
priority_queue<nod>pq;
int main(void){
scanf("%I64d",&n);
scanf("%I64d%I64d",&t,&w);
for(LL i=;i<n;++i){
LL t,w;
scanf("%I64d%I64d",&t,&w);
if(t<=w)a[k++]=nod(t,w);
}
sort(a,a+k,cmp);
for(;index<k;++index){
if(a[index].t<=t)break;
pq.push(a[index]);
}
rk=ans=index+;
while(!pq.empty()){
nod temp=pq.top();
pq.pop();
t-=temp.diff+;
if(t<)break;
LL i=;
for(;i+index<k;++i){
if(a[i+index].t<=t)break;
pq.push(a[i+index]);
}
rk+=i-;
index+=i;
ans=Min(ans,rk);
}
printf("%I64d\n",ans);
}

Contest Balloons的更多相关文章

  1. codeforces 725D . Contest Balloons(贪心+优先队列)

    题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...

  2. CodeForces - 725D Contest Balloons 贪心

              D. Contest Balloons          time limit per test 3 seconds         memory limit per test 2 ...

  3. Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心

    http://codeforces.com/contest/725/problem/D 这题一看就是贪心的了,w - t最小的那个,肯定是优先打死. 但是一直都不会写,为什么呢,因为这个太像二分答案了 ...

  4. 【37.74%】【codeforces 725D】Contest Balloons

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. Canada Cup 2016 D. Contest Balloons

    最近好弱做什么题目都是做一晚上 这是合肥站炼铜后遗症? 这题就是贪心 我已开始还写了1小时---三分-----. #include<bits/stdc++.h> using namespa ...

  6. 【CF725D】Contest Balloons(贪心,堆)

    题意:acm队伍可以得气球,相同气球数是一个排名.每个队伍有一个气球数上限,如果该队伍的气球数大于上限 该队伍被淘汰.给了你队伍的气球数,你的气球可以给别人,问你最大可能的排名. (2 ≤ n ≤ 3 ...

  7. ZOJ 3703 Happy Programming Contest

    偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 ...

  8. Codeforces 782C. Andryusha and Colored Balloons 搜索

    C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes ...

  9. ZOJ3703 Happy Programming Contest 2017-04-06 23:33 61人阅读 评论(0) 收藏

    Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 KB In Zhejiang University P ...

随机推荐

  1. mysql java写入时间少14小时

    查看时区: mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | V ...

  2. redis服务器安装-SuSE Linux Enterprise Server 11 SP3

    一.下载 官网下载,可自选版本,点击进入下载,这里下载了redis-3.2.4 放到 /root/usr/local/redis/ 目录下 二.编译 1. 执行make编译redis tar -zxz ...

  3. smbaclient

    在linux中通过smbaclient获取windows的共享文件 列出windows的共享目录 $ smbclient -L .xxx -U administrator%password 进入指定共 ...

  4. hdu 1536 S-Nim (简单sg函数)

    题意:首先输入K 表示一个集合的大小  之后输入集合 表示对于这对石子只能去这个集合中的元素的个数 之后输入 一个m 表示接下来对于这个集合要进行m次询问 之后m行 每行输入一个n 表示有n个堆  每 ...

  5. 解决 maven项目问题 An error occurred while filtering resources

    解决方法: Maven -> Update Project.

  6. JS 获取网页的宽高

    网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.body.offsetWi ...

  7. 导入spring源码到eclipse

    1.1安装Gradle 可以从http://www.gradle.org/downloads页面下载Gradle.下载后将文件解压到指定目录,我放在D:\软件\gradle-3.3,然后设置环境变量. ...

  8. oracle中关于Oracle Database 11g Express Edition 打不开的问题

    报的错误是http://127.0.0.1:...什么的找不到该文件 如果是127.0.0.1没问题,而且oracle中5个服务没问题,而且oracle可以启动.. 最后的问题是8080端口冲突,如果 ...

  9. centos-mysql 安装

    初学者自编文档,如有错误,请指出,具体命令就不阐述了,不明白 度娘吧! nginx我是编译安装在服务器上 和其他安装应该会有区别 安装路径路径:/usr/local/ 安装包存放位置:/home/ap ...

  10. 【系统设计】论文总结之:Butler W. Lampson. Hints for computer system design

    Butler W. Lampson. Hints for computer system design. ACM Operating Systems Rev. 15, 5 (Oct. 1983), p ...