题目链接: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. AngularJS Best Practices: ngRoute

    app/----- components/---------- users/--------------- controllers/-------------------- users.control ...

  2. MVC HtmlHelper用法(一)@Html.BeginForm的使用总结

    1.@using(Html.BeginForm()){}                                                      //提交到当前页面 2.@using ...

  3. 执行robot framework 的测试用例 命令行pybot使用方式

    1.执行整个项目下的所有用例: pybot 项目路径.例如: pybot D:\robot 2.执行某个suit中的所有用例: pybot 项目路径\suit文件名称. 例如:pybot D:\rob ...

  4. 全网扫描扫描10000端口后的优化脚本&域名列表指定端口的批量测试

    方法一: #coding=utf-8 import urllib2 import threading from time import ctime,sleep print "Start-Ti ...

  5. Preconditions优雅的检验参数

    Preconditions里面的方法: 1 .checkArgument(boolean) : 功能描述:检查boolean是否为真. 用作方法中检查参数 失败时抛出的异常类型: IllegalArg ...

  6. 列间距column-gap

    column-gap主要用来设置列与列之间的间距,其语法规则如下: column-gap: normal || <length> 取值说明 属性值 属性值说明 normal 默认值,默值为 ...

  7. Coursera台大机器学习基础课程学习笔记2 -- 机器学习的分类

    总体思路: 各种类型的机器学习分类 按照输出空间类型分Y 按照数据标记类型分yn 按照不同目标函数类型分f 按照不同的输入空间类型分X 按照输出空间类型Y,可以分为二元分类,多元分类,回归分析以及结构 ...

  8. jquery mobile界面数据刷新

    JQM里面当我们更新了某些页面标签(如: listview, radiobuttons, checkboxes, select menus)里的数据时,必须做refresh操作. 为什么必须做refr ...

  9. PHP排序函数

    /** * 对查询结果集进行排序 * http://www.onethink.cn * /Application/Common/Common/function.php * * @access publ ...

  10. python对json的操作总结

    Json简介:Json,全名 JavaScript Object Notation,是一种轻量级的数据交换格式.Json最广泛的应用是作为AJAX中web服务器和客户端的通讯的数据格式.现在也常用于h ...