题目链接:codeforces 725D . Contest Balloons

先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给排名在前面的的队,给完后自己的气球数减少,继续跟之前排在第一队后面的队比较,考虑是否加入队列,每次记录最好的名次。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N = ;
struct team{
ll t, w, wa;
team(ll t = , ll w = ):t(t),w(w) { wa = w - t + ; }
bool operator < (const team &r)const{
return r.wa < wa;
}
}a[N];
bool cmp(team x, team y){
return x.t > y.t;
}
priority_queue<team>q;
int main(){
int n, i, j;
ll ans, a1;
scanf("%d", &n);
for(i = ; i < n; ++i)
scanf("%lld%lld", &a[i].t, &a[i].w);
sort(a+, a+n, cmp);
for(i = ; i < n; ++i){
if(a[i].t > a[].t)
q.push(team(a[i].t, a[i].w));
else break;
}
a1 = ans = i;//初始名次
while(!q.empty()){
team tt = q.top(); q.pop();
a[].t -= tt.wa;
if(a[].t < ) break;
for(j = i; j < n; ++j){
if(a[j].t > a[].t){
q.push(team(a[j].t , a[j].w));}
else break;
}
a1 += j - i - ;
i = j;
ans = min(ans, a1);
}
printf("%lld\n", ans);
return ;
}

codeforces 725D . Contest Balloons(贪心+优先队列)的更多相关文章

  1. CodeForces - 725D Contest Balloons 贪心

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

  2. codeforces 854C.Planning 【贪心/优先队列】

    Planning time limit per test 1 second memory limit per test 512 megabytes input standard input outpu ...

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

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

  4. Educational Codeforces Round 62 (Rated for Div. 2) C 贪心 + 优先队列 + 反向处理

    https://codeforces.com/contest/1140/problem/C 题意 每首歌有\(t_i\)和\(b_i\)两个值,最多挑选m首歌,使得sum(\(t_i\))*min(\ ...

  5. Codeforces 1132D - Stressful Training - [二分+贪心+优先队列]

    题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有 $n$ 个学生,他们的电脑有初始电量 $a[1 \sim n]$,他们的电脑每分钟会耗 ...

  6. C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列

    C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  7. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...

  8. Contest Balloons

    Contest Balloons 题目链接:http://codeforces.com/problemset/problem/725/D 贪心+枚举 每次在排名在自己前面的选出w-t值最小的送气球,更 ...

  9. #433 Div2 Problem C Planning (贪心 && 优先队列)

    链接 : http://codeforces.com/contest/854/problem/C 题意 : 有 n 架飞机需要分别在 1~n 秒后起飞,允许起飞的时间是从 k 秒后开始,给出每一架飞机 ...

随机推荐

  1. postgresql运维

    0. 帮助 $/home/lhl/az/pg/bin/pg_ctl --help pg_ctl is a utility to initialize, start, stop, or control ...

  2. (地址)propedit安装说明的地址

    proedit http://propedit.sourceforge.jp/eclipse/updates/

  3. Leetcode: Find Right Interval

    Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...

  4. android IntentFilter 使用之 data过滤

    1 Intent分为两大类,显式和隐式. 显式事件,就是指通过 component Name 属性,明确指定了目标组件的事件. 比如我们新建一个Intent,指名道姓的说,此事件用于启动名为" ...

  5. Android--Retrofit+RxJava的简单封装(三)

    1,继续接着上一篇的讲讲,话说如果像上一篇这样的话,那么我们每一次请求一个结构都要创建一堆的Retrofit对象,而且代码都是相同的,我们可以试试封装一下 先创建一个HttpMethods类,将Ret ...

  6. PHP中fopen,file_get_contents,curl函数的区别

    PHP中fopen,file_get_contents,curl函数的区别 1.fopen/file_get_contents每次请求都做DNS查询,并不对DNS的信息进行缓存,而curl会对DNS的 ...

  7. Struts2&Hibernate&Spring框架目录

      第3章 Struts2框架 Struts是流行和成熟的基于MVC设计模式的Web应用程序框架 使用目的:减少在运用MVC设计模型来开发Web应用的时间 3.1 Struts2框架概述 3.1.1 ...

  8. TypeError: unsupported operand type(s) for |: 'str' and 'str'

    问题描述:

  9. Bootstrap_标签

    一.标签 在一些Web页面中常常会添加一个标签用来告诉用户一些额外的信息,比如说在导航上添加了一个新导航项,可能就会加一个“new”标签,来告诉用户. 那么在Bootstrap框架中特意将这样的效果提 ...

  10. GZFramework代码生成器插件使用教程

    代码生成器分两种 1.基于独立exe生成程序 直接运行软件目录下GZFrameworkCodeGenerate.exe文件即可 2.基于VS插件生成 目录中分为两部分:全局缓存和VS插件 1.添加全局 ...