ZOJ3410--Layton's Escape
来源:互联网 发布:oppo怎么改4g网络设置 编辑:程序博客网 时间:2024/05/22 17:05
Description
Professor Layton is a renowned archaeologist from London's Gressenheller University. He and his apprentice Luke has solved various mysteries in different places.
Unfortunately, Layton and Luke are trapped in a pyramid now. To escape from this dangerous place, they need to pass N traps. For each trap, they can use Ti minutes to remove it. If they pass an unremoved trap, they will lose 1 HP. They have K HP at the beginning of the escape and they will die at 0 HP.
Of course, they don't want trigger any traps, but there is a monster chasing them. If they haven't pass the ith trap in Di minutes, the monster will catch and eat them. The time they start to escape is 0, and the time cost on running will be ignored. Please help Layton to escape from the pyramid with the minimal HP cost.
Input
There are multiple test cases (no more than 20).
For each test case, the first line contains two integers N and K (1 <= N <= 25000, 1 <= K <= 5000), then followed by N lines, the ith line contains two integers Ti and Di (0 <= Ti <= 10^9, 0 <= Di <= 10^9).
Output
For each test case, if they can escape from the pyramid, output the minimal HP cost, otherwise output -1.
Sample Input
3 240 6060 9080 1202 130 12060 40
Sample Output
1-1
屯道题。。经典贪心。
按die排序,必须掉血的时候,在堆中拿最大cost那个。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;#define maxn 25080#define LL long long intstruct Job{LL cost,die;}job[maxn];struct Node{LL cost;bool operator < (const Node & a)const{return cost < a.cost;}};bool cmp(Job j1,Job j2){if(j1.die != j2.die)return j1.die < j2.die;else return j1.cost > j2.cost;}int gao(int n,int k){priority_queue <Node> q;LL nowtime = 0;for(int i = 1;i <= n;i++){if(nowtime + job[i].cost <= job[i].die){Node fuck;fuck.cost = job[i].cost;q.push(fuck);nowtime += job[i].cost;}else {Node temp;temp.cost = job[i].cost;nowtime += job[i].cost;q.push(temp);while(nowtime > job[i].die && !q.empty()){Node temp1 = q.top();q.pop();nowtime -= temp1.cost;k--;}}}return k;}int main(){//freopen("in.txt","r",stdin);int n,k;while(scanf("%d%d",&n,&k)==2){for(int i = 1;i <= n;i++){scanf("%lld%lld",&job[i].cost,&job[i].die);}sort(job+1,job+1+n,cmp);int a = gao(n,k);if(a <= 0) cout << -1 << endl;else cout << k - a << endl;}}
- ZOJ3410--Layton's Escape
- zoj3410 Layton's Escape (优先队列)
- zoj 3410 Layton's Escape
- zoj 3410 Layton's Escape(优先队列+贪心)
- zoj 3410 Layton's Escape(贪心+优先队列)
- ZOJ-3410-Layton's Escape_贪心
- Escape's usage
- s.decode('unicode-escape')
- [1264] Flandre\'s First Escape
- struts2 <s:property>标签的escape属性
- NOJ [1265] Flandre's Second Escape
- struts2 <s:property>标签的escape属性
- escape(s, t)函数的实现
- <s:property>标签的escape属性
- struts2的标签 s:property 的 escape
- escape
- escape
- escape
- freemaker入门例子
- iOS7新特性之后台任务-Background Multitasking
- 数的计数
- 设计模式之抽象工厂模式
- Android ActionBar应用实战,高仿微信主界面的设计
- ZOJ3410--Layton's Escape
- ESPN:韦德续约狠打LBJ脸 他诠释"忠诚大于王权"
- php 面向对象之解决单继承问题
- 查看Mysql数据库大小的SQL语句
- Python学习笔记1:安装,创建,执行
- 我的淘宝历程(二)
- 深入理解JavaScript系列 ----(17):面向对象编程之概论
- ImageView 点击效果 selector 设置
- 根域名匹配正则