Expedition [POJ2431] [贪心]】的更多相关文章

题目大意: 有n个加油站,每个加油站的加油的油量有限,距离终点都有一个距离. 一个卡车的油箱无限,每走一个单元要消耗一单元的油,问卡车到达终点的最少加多少次油. 分析: 我们希望的是走到没油的时候就尽可能加更多的油 显然我们是没办法随时获得加油的机会的 但是我们把我们走过的加油站全按从大到小记下来 没有了就加,如果加油站全都用完了,就代表gg了,puts("-1") 代码: #include<queue> #include<cstdio> #include<…
来源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…
题意: 卡车每走一个单元消耗一升汽油,中途有加油站,可以进行加油,问能否到达终点,求最少加油次数. 分析: 优先队列+贪心 代码: #include<iostream> #include<queue> #include<algorithm> using namespace std; const int maxn = 10055; typedef pair<int, int>pii; pii p[maxn]; priority_queue<int>…
题意:        给一个终点,然后给你一个卡车距离终点的距离,还有其他个加油站距离终点的距离,然后每走一个单位距离要花费一个单位油,卡车的邮箱是无限大的,而每个加油站的油量是有限的,整个路径是一个线性的,然后求到达终点的最少加油次数. 思路:        想了将近20分钟才想出来,哎! 我的方法是贪心,大体思路是这样,先给加油站排序,然后从离自己最紧的开始枚举,如果当前能到达该加油站,那么把改加油站存起来,如果到达不了,那么就从之前存的里面取一个油量最大的加油,增加了当前能到的最大程度(这…
题目链接: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…
正解:模拟费用流 解题报告: 先放个传送门鸭,题目大意可以点Descriptions的第二个切换成中文翻译 然后为了方便表述,这里强行改一下题意(问题是一样的只是表述不一样辣,,, 就是说现在在高速公路上行驶,初始有K的油量,每走一公里要消耗一单位的油,然后路上有N个加油站,离终点的距离分别为A[i],每次经过一个加油站可以选择加或者不加,加就能加B[i]的油量,然后要求路上不能存在没油的情况,问最少要加几次油 然后就考虑可以理解成,每经过一个加油站,就相当于有加油的权利,所以把它加入堆中,当没…
以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #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…
题目链接: 传送门 Expedition Time Limit: 1000MS     Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1单位距离消耗1单位的汽油.在途中一共有N个加油站.假设卡车的燃料箱容量无限大,问如果到达终点最少的加油次数. 思路 在卡车开往终点途中,只有在加油站才可以加油,换做认为"在到达加油站i时,就获得了一次在之后任何时候都可以加油的权利" #include<iostream> #in…
简单的说说思路,如果一开始能够去到目的地那么当然不需要加油,否则肯定选择能够够着的油量最大的加油站加油,,不断重复这个贪心的策略即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int maxn=1e4+9; int dist,p,n; struc…
思路:先把加油站按升序排列. 在经过加油站时.往优先队列里增加B[i].(每经过一个加油站时,预存储一下油量) 当油箱空时:1.假设队列为空(能够理解成预存储的油量),则无法到达下一个加油站,更无法到达目的地. 2.否则就取出队列里的最大元素,来给汽车加油(贪心思想) #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue>…
题目链接:http://poj.org/problem?id=2431 题目大意:一辆卡车,初始时,距离终点L,油量为P,在起点到终点途中有n个加油站,每个加油站油量有限,而卡车的油箱容量无限,卡车在行车途中,每走一个单位的距离消耗一个单位的油量,给定n个加油站距离终点的距离以及油存储量.问卡车是否能到达终点,如果可达,最少需要加多少次油,否则输出-1. 例: 输入: 44 45 211 515 1025 10 输出: 2 解题思路:采用贪心的思想,卡车当然在不加油的情况下走的越远越好了,而当它…
题目链接 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…
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 ever…
地址 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: 29360   Accepted: 8135 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…
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…
Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30702   Accepted: 8457 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…
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #inc…
直接代码... #include<string.h> #include<stdio.h> #include<queue> #include<iostream> #include<algorithm> using namespace std; struct node { int fuel,dist; //bool operator < (const node&d) const{ // return dist>d.dist; //…
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…
题目地址:CF1091F New Year and the Mallard Expedition 题意比较复杂,整理一下: \(n\) 段,每段有两个属性:长度,地形(G,W,L) 有三种运动方式: 1.游泳:W,3m/s,+1 2.走路:G,5m/s,+1 3.飞行:G,W,L,1m/s,-1 思路:贪心 需要解决两个问题: 1.遇到L时没体力飞行 解决的方法很简单:在之前的某个地方向后游泳或走路半米,再向前半米,这样可以+1 显然,游泳比走路更优,因此我们在第一次遇到W时完成所需的所有+1…
Expedition 直接中文 Descriptions 一群奶牛抓起一辆卡车,冒险进入丛林深处的探险队.作为相当差的司机,不幸的是,奶牛设法跑过一块岩石并刺破卡车的油箱.卡车现在每运行一个单位的距离泄漏一个燃料单位. 为了修理卡车,奶牛需要沿着一条蜿蜒的长路行驶到最近的城镇(距离不超过1,000,000个单位).在这条路上,在城镇和卡车的当前位置之间,有N(1 <= N <= 10,000)燃料站,奶牛可以停下来获得额外的燃料(每站1..100个单位). 丛林对人类来说是一个危险的地方,对奶…
Expedition 给出n+1个整点\(\{x_i\}\)(保证递增排序),一个司机带着初始油量p,从\(x_{n+1}\)出发,每行驶一个单位长度消耗一个油量,其中\(x_1\sim x_n\)为加油站,到达第i个加油站,可以选择获得油量\(a_i\)(不允许重复加油),询问其实你可以这样理解\(a_{n+1}=p\),开始油量为0,询问司机是否能到达原点,如果可以的话,请问最少的加油次数,\(n\leq 10000,1 <= P <= 1,000,000,x_{n+1}\leq 10^6…
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][Status][Discuss] Description FJ打算带他的N(1 <= N <= 30,000)头奶牛去参加一年一度的“全美农场主大奖赛”.在这场比赛中,每个参赛者都必须让他的奶牛排成一列,然后领她们从裁判席前依次走过. 今年,竞赛委员会在接受队伍报名时,采用了一种新的登记规则:他们把所…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15564    Accepted Submission(s): 6405 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g…
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][Status][Discuss] Description 与很多奶牛一样,Farmer John那群养尊处优的奶牛们对食物越来越挑剔,随便拿堆草就能打发她们午饭的日子自然是一去不返了.现在,Farmer John不得不去牧草专供商那里购买大量美味多汁的牧草,来满足他那N(1 <= N <= 100,…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Status][Discuss] Description 给定一个长度为n的序列a[1],a[2],...,a[n],请将它划分为m段连续的区间,设第i段的费用c[i]为该段内所有数字的异或和,则总费用为c[1] or c[2] or ... or c[m].请求出总费用的最小值. Input 第一行包含…