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. jQuery Ajax用法

    jQuery Ajax在web应用开发中很常用,它主要包括有ajax,get,post,load,getscript等等这几种常用无刷新操作方法,下面我来给各位同学介绍介绍. 我们先从最简单的方法看起 ...

  2. [Angular Directive] Assign a Structual Directive a Dynamic Context in Angular 2

     Just like passing in an array to *ngFor, you can pass in any value into your structural directive s ...

  3. Extjs的GridPanel分页前后台完整代码实例

    第一次写文章啊,有些冲动.最近在公司学习Extjs,做了一个分页的小实例和大家分享. 1.首先编写paging-grid.js文件,这是我在网上参考的例子改写的,大同小异. Ext.onReady(f ...

  4. Kubernetes(k8s)容器运行时(CRI)

    Kubernetes节点的底层由一个叫做"容器运行时"的软件进行支撑,它负责比如启停容器这样的事情.最广为人知的容器运行时当属Docker,但它不是唯一的.事实上,容器运行时这个领 ...

  5. -webkit-tap-highlight-color处理元素点击默认高亮

    -webkit-tap-highlight-color:transparent; 或者 -webkit-tap-highlight-color: rgba(0, 0, 0, 0);

  6. delphi用TAdoStoredProc调用存储过程,兼容sql2005、2008、2014的远程事务问题

    delphi7写的程序,在sql2000里没问题,调用sql2008.2014里的存储过程时,如果存储过程里操作了大量数据,很容易会莫名其妙的自己撤销掉,但是程序还识别不到,认为还在正常执行.今天尝试 ...

  7. log4j基本使用方法

    通过配置文件可知,我们需要配置3个方面的内容: 1.根目录(级别和目的地) 2.目的地(控制台和文件等) 3.输出样式 Log4j由三个重要的组件构成: 1.日志信息的优先级 日志信息的优先级从高到低 ...

  8. JavaSE中主要的类与方法

    1.instanceof:测试左边的对象是否是右边类的实例;  数组.length:返回的是数组的长度; 2.Scanner类     nextInt():读取键盘录入的整数;  next():读取键 ...

  9. Ansible Filter

    没啥好说的. 自己看吧 http://docs.ansible.com/ansible/playbooks_filters.html

  10. 【IE6的疯狂之十二】一个display:none引起的3像素的BUG

    今天同事给我看了一个display:none引起的3像素的BUG,非常奇怪!从来没碰到过display:none还能引起这种bug. 看代码:   <div style="width: ...