正解:贪心

解题报告:

先放个传送门鸭,题目大意可以点$Descriptions$的第二个切换成中文翻译

然后为了方便表述,这里强行改一下题意(问题是一样的只是表述不一样辣,,,

就是说现在在高速公路上行驶,初始有$K$的油量,每走一公里要消耗一单位的油,然后路上有$N$个加油站,离终点的距离分别为$A_i$,每次经过一个加油站可以选择加或者不加,加就能加$B_i$的油量,然后要求路上不能存在没油的情况,问最少要加几次油

然后就考虑可以理解成,每经过一个加油站,就相当于有加油的权利,所以把它加入堆中,当没油的时候从堆中找出油量$max$就好

然后就做完辣!这题还是比较水的$QAQ$

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
#define il inline
#define gc getchar()
#define t(i) edge[i].to
#define mp make_pair
#define ri register int
#define rb register bool
#define rc register char
#define lb(x) lower_bound(st+1,st+st_cnt,x)-st
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt) const int N=1e4+;
int K,f,n,nw=,as;
struct nod{int a,b;}node[N];
priority_queue<int>Q; il int read()
{
rc ch=gc;ri x=;rb y=;
while(ch!='-' && (ch<'' || ch>''))ch=gc;
if(ch=='-')ch=gc,y=;
while(ch>='' && ch<='')x=(x<<)+(x<<)+(ch^''),ch=gc;
return y?x:-x;
}
il bool cmp(nod gd,nod gs){return gd.a<gs.a;} int main()
{
freopen("2431.in","r",stdin);freopen("2431.out","w",stdout);
n=read();rp(i,,n)node[i]=(nod){read(),read()};f=read();K=read();rp(i,,n)node[i].a=f-node[i].a;sort(node+,node++n,cmp);
node[++n].a=f;node[n].b=;
rp(i,,n)
{
while(K<node[i].a && !Q.empty())K+=Q.top(),Q.pop(),++as;
if(K>=node[i].a)Q.push(node[i].b);
}
if(K>=f)printf("%d\n",as);else printf("-1\n");
return ;
}

这儿是代码鸭!

POJ2431 Expedition 贪心的更多相关文章

  1. POJ2431 优先队列+贪心 - biaobiao88

    以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #include<iostream> #include<algorithm> using namespa ...

  2. poj 2431 Expedition 贪心

    简单的说说思路,如果一开始能够去到目的地那么当然不需要加油,否则肯定选择能够够着的油量最大的加油站加油,,不断重复这个贪心的策略即可. #include <iostream> #inclu ...

  3. POJ2431 Expedition(排序+优先队列)

    思路:先把加油站按升序排列. 在经过加油站时.往优先队列里增加B[i].(每经过一个加油站时,预存储一下油量) 当油箱空时:1.假设队列为空(能够理解成预存储的油量),则无法到达下一个加油站,更无法到 ...

  4. poj2431 Expedition优先队列

    Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Bein ...

  5. poj 2431 Expedition 贪心 优先队列 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪 ...

  6. poj 2431 Expedition 贪心+优先队列 很好很好的一道题!!!

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10025   Accepted: 2918 Descr ...

  7. POJ 2431 Expedition 贪心 优先级队列

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30702   Accepted: 8457 Descr ...

  8. POJ 2431 Expedition (贪心+优先队列)

    题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...

  9. poj2431 Expedition

    直接代码... #include<string.h> #include<stdio.h> #include<queue> #include<iostream& ...

随机推荐

  1. Entity Framework定义外键,限制通过migration命令自动更改字段名称

    1.问题 在定义一个表的外键时,通过add-migration命令生成,并通过update-database更新到数据库,发现外键名称发生了重命名.举例说明: 人员表[User](Id,Name,Pa ...

  2. 回忆:NVelocity--基于.NET的模板引擎

    相关网址: http://www.castleproject.org/others/nvelocity/index.html http://www.castleproject.org/castle/d ...

  3. 记一个神奇的WAS问题:sibuswsgw-sibuswsgw_console.jar invalid LOC header (bad signature) 分类: WebSphere 2015-08-06 23:21 9人阅读 评论(0) 收藏

    今天晚上,出现了一个神奇的WAS问题,详细问题异常信息如下: [15-8-6 22:13:29:146 CST] 00000013 ApplicationMg A WSVR0203I: 应用程序:is ...

  4. vue返回上一页面如果没有上一页面返回首页

    methods: { back(){ if (window.history.length <= 1) { this.$router.push({path:'/'}) return false } ...

  5. MyBatis Generator使用com.mysql.cj.jdbc.Driver遇到的问题

    MyBatis Generator使用com.mysql.cj.jdbc.Driver Mybatis Generator 1.3.5 新建了一个decision库,并创建了一张user表 impor ...

  6. OSG模拟鼠标事件影响操纵器

    viewer->getEventQueue()->mouseButtonPress(0,0,1); viewer->getEventQueue()->mouseMotion(1 ...

  7. js 获取验证码计时器

    效果图: 贴上代码: <div class="logintitle"> <input type="tel" id="mobile&q ...

  8. Orleans学习总结(四)--集群配置篇

    上篇我们讲了Orleans学习总结(三)--持久化篇,这一篇我们来说说集群配置,毕竟这个才是Orleans的看家本领 Orleans支持热起动,支持自动节点发现,能够断线重发等一系列黑科技. 我这篇是 ...

  9. web -- Navigator.vibrate(); 使设备(有振动硬件)产生有频率的振动

    MDN 文档 此方法需要用户手势. 否则,它返回false. const koa2 = require(`koa2`); const Router = require(`koa-router`); c ...

  10. javascript parseUrl函数(来自国外的获取网址url参数)

    function parseURL(url) { var a = document.createElement('a'); a.href = url; return { source: url, pr ...