GYM 100090 I.Retakes(贪心+优先队列)
来源:互联网 发布:厄米特矩阵的逆也是 编辑:程序博客网 时间:2024/05/21 10:04
Description
补考n场考试,每场考试有一个开始日期和补考费用,而且超过日期也需付出和超出日期天数一样的费用,问如果安排补考使得每场考试的花费中的最大值最小
Input
第一行一整数n表示考试数目,之后n行每行两个整数t[i]和c[i]分别表示第i场考试的开始时间和补考费用,保证t非减(1<=n<=200000,1<=t[i]<=1e6,0<=c[i]<=1e9)
Output
输出n个整数表示在花费最小下每场考试的日期
Sample Input
3
1 3
1 1
2 4
Sample Output
1 3 2
Solution
每天肯定要考当前需要考的考试中花费最大的,这样就尽可能的降低了花费中的最大值,由于延迟考试的额外花费,不能直接把c[i]看作这场考试的花费,而是把c[i]-t[i]看作这场考试的花费,之后就是游标法,一个表示日期,另一个表示考试,对于每个日期把当前可以考的考试的花费放进优先队列里,每天从优先队列中拿出最大值作为当天要考的试即可
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define maxn 222222int n,t[maxn],c[maxn],ans[maxn];struct node{ int v,id; node(){}; node(int _v,int _id) { v=_v,id=_id; } bool operator<(const node& b)const { return v<b.v; }};priority_queue<node>que;int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++)scanf("%d%d",&t[i],&c[i]),c[i]-=t[i]; while(!que.empty())que.pop(); for(int i=1,j=1;i<=1e6+n;i++) { while(j<=n&&t[j]<=i)que.push(node(c[j],j)),j++; if(!que.empty()) { node now=que.top(); que.pop(); ans[now.id]=i; } if(j==n+1) { while(!que.empty()) { node now=que.top(); que.pop(); ans[now.id]=++i; } } } for(int i=1;i<=n;i++) printf("%d%c",ans[i],i==n?'\n':' '); }}
0 0
- GYM 100090 I.Retakes(贪心+优先队列)
- Gym Class(优先队列+拓扑排序)
- hdu5695(拓扑+优先队列)Gym Class
- GYM 100247 I. Meteor Flow(贪心)
- GYM 100030 I.Prohibition(贪心)
- poj1042(贪心+优先队列)
- POJ1456Supermarket(贪心+优先队列)
- poj3465(贪心+优先队列)
- poj2431Expedition(贪心,优先队列)
- 推销员(优先队列+贪心)
- poj3190(贪心,优先队列)
- Sunscreen (贪心+优先队列)
- 【2016-北京赛区网络赛-I】枚举,贪心,优先队列,优化(导弹,hihocoder 1391)
- Gym 101617Jbfs+优先队列
- HDU-5695-Gym Class(拓扑排序+优先队列)
- HDU 5695 Gym Class(优先队列+拓扑排序)
- HDU 5695 Gym Class (拓扑排序+优先队列+Vector)
- HDU 5695 Gym Class(拓扑排序,优先队列)
- Opencv 去高光或镜面反射(illuminationChange)
- 素数的判定
- Ubuntu14.04下安装的owncloud8实现https访问
- 浅触数组列表
- 使用matplotlib画简单的等高线图
- GYM 100090 I.Retakes(贪心+优先队列)
- NGUI与UGUI
- javascript闭包操作
- 第五届蓝桥杯【省赛试题1】啤酒和饮料
- [Codeforces570D]Tree Requests(dsu on the tree)
- kmalloc分配大小的限制
- Fiddler2中文乱码问题
- swfit 的 get 和 set 方法, willSet 和 didSet
- Android系统源码下载搭建步骤