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. .NET并行与多线程学习系列一

    并行与多线程学习系列一 一.并行初试: public static void test() { ; i < ; i++) { Console.WriteLine(i); } } public s ...

  2. 【算法专题】工欲善其事必先利其器—— C++ STL中vector(向量/不定长数组)的常用方法总结

    #include<iostream> #include<cstdio> #include<string> #include<vector>//不定长数组 ...

  3. iOS开发-UI (一)常用控件

    从这里开始是UI篇 知识点: 1.常用IOS基本控件 2.UITouch ======================= 常用基本控件 1.UISegmentedControl:分段控制器 1)创建方 ...

  4. windows系统下快捷命令

    mstsc 远程计算机 regedit 注册表

  5. pythong下的unittest框架

    今天有空测试了下TestSuit的执行顺序,用discover遍历过来的tests,用runner执行. 只会识别继承了unittest的测试类中的测试用例.按setup和teardown的顺序进行执 ...

  6. Netty 5.0源码分析-ByteBuf

    1. 概念 Java NIO API自带的缓冲区类功能相当有限,没有经过优化,使用JDK的ByteBuffer操作更复杂.故而Netty的作者Trustin Lee为了实现高效率的网络传输,重新造轮子 ...

  7. 不要错过 DevOps 之父出席的2017 DevOpsDays 北京站!

    通过 DevOpsDays 活动,Patrick 将 DevOps 这项伟大的运动带到了地球的东方,带到了北京.同时,他将亲自参加2017年3月18日的 DevOpsDays 北京站,并作精彩演讲. ...

  8. 【游记】NOIP2015造纸记

    题目来自HZWER学长的名言:“虽然已经做好了学OI就是打铁的准备.” 然后我发现我已经不是打铁,只能造纸了啊_(:3LZ_) [DAY0] 中午吃了饭才1:00,说好2:30才出发于是各种闲逛.2: ...

  9. java 的序列化

    (1) 首先是java自己内部实现的对象序列化机制 其实就是ObjectInputStream 和 ObjectOutputStream 首先实现一个实体对象  记住必须实现Serializable ...

  10. Egret 显示容器

    1,显示容器:所有的容器都继承自DisplayObjectContainer , DisplayObjectContainer 又继承自DisplayObject: 2,想定义一个容器只要创建一个类, ...