Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. On this way, the tourists in the bus can see the sights alongside the route travelled. Moreover,…
http://poj.org/problem?id=3463 Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 2270 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from…
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: 说实话,上次写类似的二维状态最短路Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra],我没能把手写二叉堆优化Dijkstra的给写出来. 这次费了点功夫,也算是给写出来了,需要注意的点还是有点多的.而且我终于深刻理解为啥不推荐手写二叉堆了,主要是代码量相比…
F - Sightseeing 传送门: POJ - 3463 分析 一句话题意:给你一个有向图,可能有重边,让你求从s到t最短路的条数,如果次短路的长度比最短路的长度多1,那么在加上次短路的条数. 这道题唯一要注意的就是次短路的求法 首先题目中说从起点到终点至少有一条路径,所以我们就不用考虑不可达的情况 我们先考虑如果a到b有一条边,b到c有一条边 那么a到c经过b的路程中次短路只有两种选择,一种是a到b的最短路+b到c的次短路,另一种是a到b的次短路+b到c的次短路 所以我们只需要记录次短路…
题目大意: 希望求出走出最短路的方法总数,如果次短路只比最短路小1,那也是可取的 输出总的方法数 这里n个点,每个点有最短和次短两种长度 这里采取的是dijkstra的思想,相当于我们可以不断找到更新到的最短长度来更新其他长度,保证之前的所有可取的最短长度都已经更新的情况下,这样是除了第一个点的最短路为0已知,还需要更新2*n-1次,如果从一个点的位置出发更新了其他点,那么这个位置就不再作为可更新点--这里都是暴力找最优的可更新的点--不知道如何做到像普通的dijkstra那种log级别的找点-…
题目 Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. On this way, the tourists in the bus can see the sights alongside the route travelled. Moreover, the bus…
dijkstra(最短路)和Prim(最小生成树)下的堆优化 最小堆: down(i)[向下调整]:从第k层的点i开始向下操作,第k层的点与第k+1层的点(如果有)进行值大小的判断,如果父节点的值大于子节点的值,则修改,并继续对第k+1层与第k+2层的点进行判断和修改,否则不修改,且退出.当点向下移动到树的最后一层,没有子节点供判断与修改,停止操作. 树最多有log(n) 层[log(n)=log2n,一般省略数字2],时间复杂度log(n)次. up(i)[向上调整]:同理,时间复杂度log(…
Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9247   Accepted: 3242 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. O…
/*  *题目大意:  *在一个有向图中,求从s到t两个点之间的最短路和比最短路长1的次短路的条数之和;  *  *算法思想:  *用A*求第K短路,目测会超时,直接在dijkstra算法上求次短路;  *将dist数组开成二维的,即dist[v][2],第二维分别用于记录最短路和次短路;  *再用一个cnt二维数组分别记录最短路和次短路的条数;  *每次更新路径的条数时,不能直接加1,,应该加上cnt[u][k],k为次短路径或者最短路径的标记;  *图有重边,不能用邻接矩阵存储;  *不知道…
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的T-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? Input 输入包括多组数据. 每组数据第一行是两个整数NN ,MM (N≤100N≤100 ,M≤10000M≤1000…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1688 题意:第k短路,这里要求的是第1短路(即最短路),第2短路(即次短路),以及路径条数,最后如果最短路和次短路长度差1,则输出两种路径条数之和,否则只输出最短路条数. 思路:dijkstra变形,注意状态的转移,代码上附了注释,就不多说了.. 代码: #include <bits/stdc++.h> #define MAXN 1010 using namespace std; vector&l…
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from t…
题意:求最短路和比最短路长度多1的次短路的个数 本来想图(有)方(模)便(版)用spfa的,结果妹纸要我看看dijkstra怎么解.... 写了三遍orz Ver1.0:堆优化+邻接表,WA //不能用堆优化+邻接表,因为需要处理dis[i][0]和dis[i][1]两套,如果都挤到一个堆里就乱套了 #include <iostream> #include <cstdio> #include <queue> #include <cstring> #inclu…
http://poj.org/problem?id=3463 http://acm.hdu.edu.cn/showproblem.php?pid=1688 求出最短路的条数比最短路大1的次短路的条数和,基本和上题一样,最后需判断是否满足dist[t][0]+1==dist[t][1]; cnt[i][0]表示到达点i最短的路有多少条,cnt[i][1]表示次短的条数 dist[i][0]表示到达点i最短路的长度,dist[i][1]表示次短路的长度 用v去松驰u时有四种情况 (设当前dist[v…
题目链接:http://poj.org/problem?id=2449 "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. "Prince Remmarguts lives in his kingdom UDF – Unite…
http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6776   Accepted: 1822 Description Lily runs a repairing company that services the Q blocks in the city. One day the company receives M repa…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24249   Accepted: 8652 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way pa…
感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 money=(nowmoney-手续费)*rate,现在问你有v钱,从s开始出发交换钱能不能赚钱 题解:这题其实是用bellman_ford的思想,通过n-1次松弛后,如果还能增加,就说明有环 可以使金钱数不断增加. #include <iostream> #include<cstdio>…
http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6120   Accepted: 2455 Description You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will a…
题目链接:http://poj.org/problem?id=3662 Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8248   Accepted: 2977 Description Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncoopera…
题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip through Europe this summer, you realised that the gas prices varied between the cities you visited. Maybe you could have saved some money if you were…
Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 29625   Accepted: 8034 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, h…
Roadblocks http://poj.org/problem?id=3255 Time Limit: 2000MS   Memory Limit: 65536K       Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too quick…
链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#problem/D Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21206   Accepted: 6903 Description Freddy Frog is sitting on a stone in the…
题目链接 题意 有\(n\)个牛棚,每个牛棚初始有\(a_i\)头牛,最后能容纳\(b_i\)头牛.有\(m\)条道路,边权为走这段路所需花费的时间.问最少需要多少时间能让所有的牛都有牛棚可待? 思路 二分 因为问题具有单调性,因此考虑二分时间,\(check\)是否满足条件. 满足条件指什么呢? 是指所有的牛都有牛棚可待. 是指所有的牛都顺利地从某一个牛棚移动到了另一个合法的牛棚(或者不移动),而这个移动是在限定的时间范围内的. 建图 首先拆点,将牛棚拆成 初始牛棚 与 终态牛棚. 在 源点…
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23055   Accepted: 8328 Description Several currency exchange points are working in our city. Let us suppose that each point specializes…
ROADS Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12436 Accepted: 4591 Description N cities named with numbers 1 - N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that…
题意就是要求第K短的路的长度(S->T). 对于K短路,朴素想法是bfs,使用优先队列从源点s进行bfs,当第K次遍历到T的时候,就是K短路的长度. 但是这种方法效率太低,会扩展出很多状态,所以考虑用启发式搜索A*算法. 估价函数 = 当前值 + 当前位置到终点的距离,即F(p) = G(p) + H(p). G(p): 当前从S到p所走的路径距离 H(p): 当前点p到终点T的最短路径距离   ---可以先将整个图边方向取反然后以T为源点求个最短路,用SPFA提速 F(p): 从S按照当前路径…
有n个节点的m条无向边的图,节点编号为1~n 然后有点权和边权,给出q个询问,每一个询问给出2点u,v 输出u,v的最短距离 这里的最短距离规定为: u到v的路径的所有边权+u到v路径上最大的一个点权的和(点权也可以是u,v) n<=1000 m<=20000 Q<=20000 时限:5000ms 没有点权的话,好处理 加了点权呢? 我们可以先枚举n个节点,跑n次spfa,当枚举节点u时,我们默认节点u是所有路径上点权最大的一个点 即我们枚举节点u时,我们先把点权比u大的节点删除了,在剩…
题目 这里的dijsktra的变种代码是我看着自己打的,终于把代码和做法思路联系上了,也就是理解了算法——看来手跟着画一遍真的有助于理解. #define _CRT_SECURE_NO_WARNINGS #include<string.h> #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; ; #define typec double const typec…