这题说的是 一辆汽车 每走一单位的距离就消耗一单位的燃料,然后,他要回城里去,当然他与城镇之间有n个加油站 ,他的油箱可以为 无穷大 ,这样分析后发现进不进汽油站 与 汽油站在哪无关 ,只与加油站的 汽油有关 (当然是他能到达的加油站)然后直接贪心

#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的更多相关文章

  1. [LeetCode] Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  2. Buffer cache hit ratio性能计数器真的可以作为内存瓶颈的判断指标吗?

    Buffer cache hit ratio官方是这么解释的:“指示在缓冲区高速缓存中找到而不需要从磁盘中读取的页的百分比.” Buffer cache hit ratio被很多人当做判断内存的性能指 ...

  3. LeetCode Design Hit Counter

    原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...

  4. Breakpoint is not hit

    新拿到一个Silverlight项目,能够正常运行,但是一旦运行起来,断点处由实心点变成了空心的,并警告:The breakpoint will not currently be hit. No sy ...

  5. POJ 2051

    http://poj.org/problem?id=2051 这个题目的大题意思就是给你一些ID,和ID所对应的周期,每隔它所对应的周期,它的任务就会执行,就会输出所对应的ID Register 20 ...

  6. 算法手记 之 数据结构(堆)(POJ 2051)

    一篇读书笔记 书籍简评:<ACM/ICPC 算法训练教程>这本书是余立功主编的,代码来自南京理工大学ACM集训队代码库,所以小编看过之后发现确实很实用,适合集训的时候刷题啊~~,当时是听了 ...

  7. poj 2051.Argus 解题报告

    题目链接:http://poj.org/problem?id=2051 题目意思:题目有点难理解,所以结合这幅图来说吧---- 有一个叫Argus的系统,该系统支持一个 Register 命令,输入就 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 基于spring-cloud的微服务(4)API网关zuul

    API网关是微服务架构中的很重要的一个部分,内部有多个不同的服务提供给外部来使用,API网关可以对外做统一的入口,也可以在网关上做协议转换,权限控制和请求统计和限流等其他的工作 spring-clou ...

  2. [转]Android Activity的加载模式和onActivityResult方法之间的冲突

    前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ...

  3. thinkCMF----自定义配置调用

    有些时候,需要在后台给网站一些其他的配置: 这个配置,一般都是通过修改代码实现的,ThinkCMF本身没有这个配置: 找到site.html 增加一个Group就可以: 在配置里面做相应的配置就可以:

  4. hihocoder 1284 - 机会渺茫

    N有N_cnt个约数,M有M_cnt个约数,那么总共有N_cnt * M_cnt种对应情况. 假设其中有D_cnt个对应结果是相等的,而这D_cnt个数正好是gcd(N,M)的所有约数. 例如: N= ...

  5. Linux free命令详解

    前段时间有个项目的用C写的,性能测试时发现内存泄露问题.关于怎么观察内存使用问题,free是很好用的一个命令. 参数讲解 bash-3.00$ freetotal       used       f ...

  6. Git:上传GitHub项目操作步骤

    git教程:git详解.gitbook #首次上传步骤 首先在工程文件位置处右键git bash here 本地创建ssh key $ ssh-keygen -t rsa -C "your_ ...

  7. android java epson串口打印机

    package com.common.util.portprinter; import java.io.IOException; import java.io.OutputStream; import ...

  8. w_scripting_language

    https://en.wikipedia.org/wiki/Scripting_language A scripting or script language is a programming lan ...

  9. B-tree indexes

    High Performance MySQL, Third Edition by Baron Schwartz, Peter Zaitsev, and Vadim Tkachenko http://d ...

  10. LightOj 1265 - Island of Survival(概率)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1265 题目大意:有一个生存游戏,里面t只老虎,d只鹿,还有一个人,每天都要有两个生物碰 ...