H - Expedition 优先队列 贪心】的更多相关文章

来源poj2431 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 fuel every…
poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这样,行驶过这段距离之后还能走更远的距离. 将输入的数据进行排序处理,按照位置的先后.注意输入的距离是与终点的,要转化成与起点的. 代码: #include <iostream> #include <algorithm> #include <stdio.h> #include…
以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #include<iostream> #include<algorithm> using namespace std; struct node { int x; int y; bool operator<(const node &a) const//此操作是对操作符"<"进行重构 { return x < a.x;//对结构体数组x进行从大到小排序 // retur…
Buy and Resell Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2441    Accepted Submission(s): 924 Problem Description The Power Cube is used as a stash of Exotic Power. There are n cities numbe…
题意: 卡车每走一个单元消耗一升汽油,中途有加油站,可以进行加油,问能否到达终点,求最少加油次数. 分析: 优先队列+贪心 代码: #include<iostream> #include<queue> #include<algorithm> using namespace std; const int maxn = 10055; typedef pair<int, int>pii; pii p[maxn]; priority_queue<int>…
题目地址:http://www.51cpc.com/web/problem.php?id=1587 Summarize: 优先队列&贪心: 1. 按价值最高排序,价值相同则按完成时间越晚为先: 2. 使用数组记录时间节点是否有任务,时间节点从最晚倒序遍历: 3. 若此刻时间节点有任务,则从此时间节点往前推,直到某一刻无任务,否则放弃该任务: 附贪心代码: (此处并未使用优先队列,以vector代替) #include<iostream> #include<algorithm>…
题目链接 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 fuel…
题目链接: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…
1350: To Add Which? Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 303     Solved: 134 Description There is an integer sequence with N integers. You can use 1 unit of cost to increase any integer in the sequence b…