HIT 2051
#include<string.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct point {
int dist,pow,num;
bool operator <(const point &b) const{
if(pow<b.pow) return true;
else return false;
}
};
point P[100005];
bool cmp(point a,point b)
{
if(a.dist>b.dist) return true;
else return false;
}
bool mark[100005];
int main()
{
int i,n,num;
point T,W;
priority_queue<point>Q;
while(scanf("%d",&n)==1){
while(!Q.empty())Q.pop();
num=0;
memset(mark,true,sizeof(mark));
for(i=0;i<n;i++)
scanf("%d%d",&P[i].dist,&P[i].pow);
sort(P,P+n,cmp);
scanf("%d%d",&T.dist,&T.pow);
for(i=0;i<n;i++)
P[i].num=i;
T.num=-1;
Q.push(T);
while(!Q.empty()){
Q.pop();
if(T.pow>=T.dist) break;
for(i=T.num+1;i<n;i++)
if(T.pow-(T.dist-P[i].dist)>=0&&mark[i]){
Q.push(P[i]);
mark[i]=0;
}
if(Q.empty()) break;
W=Q.top();
if(W.dist>T.dist){
T.pow+=W.pow;
}
else{
W.pow+=T.pow-(T.dist-W.dist);
T=W;
}
num++;
if(T.pow>=T.dist) break; }
if(T.pow>=T.dist)printf("%d\n",num);
else printf("-1\n");
}
return 0;
}
HIT 2051的更多相关文章
- [LeetCode] Design Hit Counter 设计点击计数器
		
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
 - Buffer cache hit ratio性能计数器真的可以作为内存瓶颈的判断指标吗?
		
Buffer cache hit ratio官方是这么解释的:“指示在缓冲区高速缓存中找到而不需要从磁盘中读取的页的百分比.” Buffer cache hit ratio被很多人当做判断内存的性能指 ...
 - LeetCode Design Hit Counter
		
原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...
 - Breakpoint is not hit
		
新拿到一个Silverlight项目,能够正常运行,但是一旦运行起来,断点处由实心点变成了空心的,并警告:The breakpoint will not currently be hit. No sy ...
 - POJ 2051
		
http://poj.org/problem?id=2051 这个题目的大题意思就是给你一些ID,和ID所对应的周期,每隔它所对应的周期,它的任务就会执行,就会输出所对应的ID Register 20 ...
 - 算法手记 之 数据结构(堆)(POJ 2051)
		
一篇读书笔记 书籍简评:<ACM/ICPC 算法训练教程>这本书是余立功主编的,代码来自南京理工大学ACM集训队代码库,所以小编看过之后发现确实很实用,适合集训的时候刷题啊~~,当时是听了 ...
 - poj  2051.Argus  解题报告
		
题目链接:http://poj.org/problem?id=2051 题目意思:题目有点难理解,所以结合这幅图来说吧---- 有一个叫Argus的系统,该系统支持一个 Register 命令,输入就 ...
 - most queries (more than 90 percent) never hit the database at all but only touch the cache layer
		
https://gigaom.com/2011/12/06/facebook-shares-some-secrets-on-making-mysql-scale/ Facebook shares so ...
 - NGUI Camera's raycast hit through the UI Layer issue
		
Raycast into GUI?http://forum.unity3d.com/threads/raycast-into-gui.263397/ << ; Ray myray = UI ...
 
随机推荐
- 8.20 前端 js
			
2018-8-20 17:40:12 js参考: https://www.cnblogs.com/liwenzhou/p/8004649.html 2018-8-20 20:33:31 css学完了 ...
 - 170814、Java使用gzip压缩文件、还原文件
			
package com.rick.utils; import java.io.*; import java.util.zip.GZIPInputStream; import java.util.zip ...
 - php intval的取值范围:与操作系统相关
			
php intval的取值范围:与操作系统相关,32位系统上为-2147483648到2147483647,64位系统上为-9223372036854775808到922337203685477580 ...
 - KMP算法小记
			
Knuth-Morris-Pratt算法: 转载来自http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_ ...
 - 区块链,Ethereum-Wallet
			
https://blockchain.info/charts/transactions-per-second https://slock.it/ https://en.wikipedia.or ...
 - CGPoint->NSValue
			
http://blog.sina.com.cn/s/blog_65a8ab5d0101c0n2.html CGPoint point = CGPointMake(self.superview.nim_ ...
 - nginx处理问题笔记
			
1. 处理所有请求到单一入口 ( rewrite all requests to index.php with nginx ) 目前我们做开发一般都是单入口的,所以都会使用web服务器做重定向到入口 ...
 - Mybatis插入数据后返回主键id
			
有时候使用mybatis插入数据后,需要用到记录在数据库中的自增id,可以利用keyProperty来返回,赋值给实体类中的指定字段. 单条记录插入并返回 First, if your databas ...
 - Excel-字符串连接
			
使用函数concatenate()将多个字符连接起来
 - Monkey and Banana---hdu1069(dp)
			
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意就是给你n种长方体每种类型不限制个数,然后我们把它们一个个堆起来,并且要满足下面的要比上面的 ...