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 ...
随机推荐
- zabbix高级玩法之通过xml文件一次性导入
author:headsen chen date: 2018-11-10 10:08:38 背景:zabbix的硬件监控架构已经部署完成,接下来就是创建主机这一步,2400台主机如果采用一台台的创 ...
- Android.mk 用法介绍
一个Android.mk file用来向编译系统描述你的源代码.具体来说:该文件是GNU Makefile的一小部分,会被编译系统解析一次或多次.你可以在每一个Android.mk file中定义一个 ...
- DragonBones龙骨换装(局部换装+全局换装)
参考: Egret官方换装动画 Egret换装三种方式 CSDN(全局换装) egret使用DragonBones实现简单的换装 换装,主要是替换任意插槽的图片,来达到局部换装的目的. 游戏中可以只制 ...
- 23种设计模式之适配器模式(Adapter)
适配器模式将一个接口转换成客户希望的另一个接口,从而使接口不兼容的那些类可以一起工作.适配器模式既可以作为类结构型模式,也可以作为对象结构型模式.在类适配器模式中,通过使用一个具体类将适配者适配到目标 ...
- iOS property中的strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
iOS5中加入了新知识,就是ARC,其实我并不是很喜欢它,因为习惯了自己管理内存.但是学习还是很有必要的. 在iOS开发过程中,属性的定义往往与retain, assign, copy有关,我想大家都 ...
- java的HashMap 原理
https://www.cnblogs.com/chengxiao/p/6059914.html 哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比 ...
- Ubuntu16.04双网卡主备配置
前几日写了一篇Ubuntu14.04双网卡主备配置,没成想变化总是这么快,今日安装某软件,提示最匹配的ubuntu版本是16.04,作为一个码农能有什么办法,只能不断去适应变化.拥抱变化. 首先16. ...
- JQuery EasyUI 日期控件 怎样做到只显示年月,而不显示日
标题问题的答案在OSChina中 http://www.oschina.net/question/2282354_224401?fromerr=lHJTcN89 我还是把这个记录下来 ======== ...
- opencv学习笔记霍夫变换——直线检测
参考大佬博文:blog.csdn.net/jia20003/article/details/7724530 lps-683.iteye.com/blog/2254368 openCV里有两个函数(比较 ...
- CodeForces 551C - GukiZ hates Boxes - [二分+贪心]
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...