POJ 2431 (优先队列)】的更多相关文章

汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油量大于0. 虽然是道挺水的题目,但还是要注意细节... /** @Date : 2017-09-21 22:45:37 * @FileName: POJ 2431 优先队列.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.…
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #inc…
poj 2431 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's fuel tank. The truck now leaks one unit of…
POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock an…
http://poj.org/problem?id=2431 你需要驾驶一辆卡车做一次长途旅行,但是卡车每走一单位就会消耗掉一单位的油,如果没有油就走不了,为了修复卡车,卡车需要被开到距离最近的城镇,在当前位置和城镇之间有n个加油站可以加油. 为了减少危险,需要最少的加油次数,卡车的油箱可以看作无限大,卡车初始距离城镇L单位,自身有P单位的油. 注意输入的距离是与城镇的距离不是与开始点的距离.转换一下就好. 思想:把经过的所有加油站都加入优先队列,当燃料不足时就取出优先队列的最大元素,用来给卡车…
题目链接:http://poj.org/problem?id=2431 题意:一辆卡车要行驶L单位距离,卡车上有P单位的汽油.一共有N个加油站,分别给出加油站距终点距离,及加油站可以加的油量.问卡车能否到达终点?若不能输出-1,否则求出最少加油次数. 解题思路:可以认为"在到达加油站时,获得一次可以在任何时候使用这个加油站加油的资格",而在之后需要加油时,就认为是在之前经过的加油站加的油就可以了.因为希望加油次数最少,所以在燃料不够行驶时选择加油量最大的加油站加油.为了高效性,我们可以…
链接:http://poj.org/problem?id=2431 题解 #include<iostream> #include<algorithm> #include<queue> using namespace std; ; int N,L,P; //N是加油站数,L是路程,P是初始燃料量 struct node{ int a, b; //a是加油站到城镇(终点)的距离,b是每个加油站燃料量 }code[MAX_N]; bool comp(node x, node…
每次写poj的题都很崩溃,貌似从来没有一次一发就ac的,每次都有特别多的细节需要考虑.还有就是自己写的太粗糙了,应该把每种情况都想到的,总是急着交,然后刷一页wa. 优先队列直接用stl就可以,简单实用. #include <iostream> #include <cstring> #include <string> #include <map> #include <set> #include <algorithm> #include…
地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪枝 然而 还是TLE了 TLE代码 #include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; vector<pair&l…
Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10025   Accepted: 2918 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed t…