Contest Balloons
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的更多相关文章
- codeforces 725D . Contest Balloons(贪心+优先队列)
题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...
- CodeForces - 725D Contest Balloons 贪心
D. Contest Balloons time limit per test 3 seconds memory limit per test 2 ...
- Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心
http://codeforces.com/contest/725/problem/D 这题一看就是贪心的了,w - t最小的那个,肯定是优先打死. 但是一直都不会写,为什么呢,因为这个太像二分答案了 ...
- 【37.74%】【codeforces 725D】Contest Balloons
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Canada Cup 2016 D. Contest Balloons
最近好弱做什么题目都是做一晚上 这是合肥站炼铜后遗症? 这题就是贪心 我已开始还写了1小时---三分-----. #include<bits/stdc++.h> using namespa ...
- 【CF725D】Contest Balloons(贪心,堆)
题意:acm队伍可以得气球,相同气球数是一个排名.每个队伍有一个气球数上限,如果该队伍的气球数大于上限 该队伍被淘汰.给了你队伍的气球数,你的气球可以给别人,问你最大可能的排名. (2 ≤ n ≤ 3 ...
- ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 ...
- Codeforces 782C. Andryusha and Colored Balloons 搜索
C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes ...
- 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 ...
随机推荐
- Jmeter对基于websocket协议的压力测试
WebSocket protocol 是HTML5一种新的协议.它实现了浏览器与服务器全双工通信(full-duplex). 浏览器和服务器只需要要做一个握手的动作,然后,浏览器和服务器之间就 ...
- 为什么用Object.prototype.toString.call(obj)检测对象类型?
最近做了做一些js面试25 Essential JavaScript Interview Questions*,其中第一道是:使用typeof bar === "object"检测 ...
- 《Dynamic Topic Detection and Tracking: A Comparison of HDP, C-Word, and Cocitation Methods》笔记
原文地址:http://onlinelibrary.wiley.com/doi/10.1002/asi.23134/abstract 黄色背景是我认为比较重要的,红色字体是我自己的话. 动态主题监测与 ...
- 基于C++的类编程总结
1. 类中public, protected, private这三个属性的区别: public意味着所有事物都能查询具有该属性的食物.(也即所有人可以在我不知情的情况下,查看我账户里还有多少钱). p ...
- CG 标准函数库
(1)数学函数 函数 功能描述 abs(x) 返回输入参数的绝对值 acos(x) 反余切函数,输入参数范围为[-1,1], 返回[0,π]区间的角度值 all(x) 如果输入参数均不为0,则返回tu ...
- hdu1116回溯N皇后问题
题目连接 经过思考,不难发现:恰好N个皇后放在不同行不同列,那么是不是可以转换成N个皇后所在行分别确定(一人一行)的情况下对她们的所在列的枚举. 也就是列的全排列生成问题,我们用c[x]表示x行皇后的 ...
- android studio Activity标题栏研究
第一次研究时间:2016/7/30,以下研究主要存在于当前最新版本的android studio上.eclipse请参考 一.头部标题取消 当前版本新建工程在 application中默认主题为 an ...
- bitcode 关于讯飞
在真机调试的时候一直报 ld: '/Users/Chenglijuan/Documents/语音识别/lib/iflyMSC.framework/iflyMSC(IFlyRecognizerView. ...
- Linux中一些简单命令(一)
1.查看当前用户:who 2.显示当前目录:pwd 3.查看当前服务器的时间:date 4.查看日历:cal+year; 例如:cal 2016 5.计算器:bc 退出计算器:quit或者ctrl+ ...
- WebForm 文件上传
//Button1的点击事件 //FileUpload1.FileName为所传文件的名字. //以DateTime.Now.ToString("yyyyMMddhhmmssms" ...