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 ...
随机推荐
- Excel 2007表格内输入http取消自动加上超链接的功能
经常使用Excel表格工作的也许会发现,当我们在表格内输入http://XXXX时,默认情况下都会自动加上超链接,如下: 当我们点击域名准备编辑修改时,往往都会调用浏览器转到该域名之下,达不到编辑修改 ...
- 【BZOJ4355】Play with sequence 线段树
[BZOJ4355]Play with sequence Description 维护一个长度为N的序列a,现在有三种操作: 1)给出参数U,V,C,将a[U],a[U+1],...,a[V-1],a ...
- PAT甲1115 Counting Nodes in a BST【dfs】
1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tr ...
- LINUX系统中安装ORACLE11g的安装文档,含部分问题解答
1.无法使用命令 /usr/bin/xdpyinfo 自动检查显示器颜色 在linux as5下安装oracle11g,环境都配置好了!等运行./runInstaller的时候无法弹出安装的图形界面我 ...
- html中label及加上属性for之后的用法
定义和用法 <label> 标签为 input 元素定义标签(label). label 元素不会向用户呈现任何特殊的样式.不过,它为鼠标用户改善了可用性,因为如果用户点击 label 元 ...
- Linux IO模式及 select、poll、epoll详解及源码(转)
原文:https://segmentfault.com/a/1190000003063859 我只摘取了其中的epoll代码示例,服务端代码 #define IPADDRESS "127.0 ...
- IO流(4)重命名
重命名功能:public boolean renameTo(File dest) * 如果路径名相同,就是改名. * 如果路径名不同,就是改名并剪切. * * 路径以盘符开始:绝对路径 c:\\a.t ...
- 第四课:通过配置文件获取对象(Spring框架中的IOC和DI的底层就是基于这样的机制)
首先在D盘创建一个文件hero.txt,内容为:com.hero.Hero(此处必须是Hero的完整路径) 接下来是Hero类 package com.hero; public class Hero ...
- myeclipse maven工程调试调试
1:使用了maven带的tomca插件进行启动.下面讲一下如何进行调试程序 2:在程序中打断点 3:选择>debug>debug configuration 在goals处添加启动命令 4 ...
- [py]监控内存并出图
监控内存出图 先将内存数据搞到数据库 已使用内存算法 used = int(total) - int(free) - int(butffers) - int(cache) pymysql模块使用 db ...