POJ 2677 Tour】的更多相关文章

Description John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must determine the shortest closed tour that connects his destinations. Each destination is r…
题意:双调欧几里得旅行商问题.算法导论15-1题,从最左边的点严格从左走到右再从右走到左回到起点,所有点都要走且只走一次,求最短路径. 解法:定义dp[i][j]表示从i走到j的双调路径,分为两种情况: 当j < i - 1时,dp[i][j] = dp[i - 1][j] + dis[i - 1][i] 当j = i - 1时,dp[i][j] = min{dp[j][k] + dis[j][k]} 最初的情况是dp[2][1] = dis[2][1]. 代码: #include<stdio…
Farm Tour 题目: 约翰有N块地,家在1号,而N号是个仓库.农场内有M条道路(双向的),道路i连接这ai号地和bi号地,长度为ci. 约翰希望依照从家里出发,经过若干地后达到仓库.然后再返回家中.假设要求往返不能经过同一条道路两次,求參观路线总长度最小值. 算法分析: 用最短路求解然后在删除第一次最短路中的边在求解一次最短路.这样是否可行?应该立即就能找到反例证明该方法不能总得到最优结果吧. 于是我们放弃把问题当作去和回的这样的想法,转而将问题当作求从1号顶点到N号顶点的两条没有公共边的…
最近正好需要用到最小费用最大流,所以网上就找了这方面的代码,动手写了写,先在博客里存一下~ 代码的题目是POJ2135-Farm Tour 需要了解算法思想的,可以参考下面一篇文章,个人觉得有最大流基础的童鞋,看了基本就能看懂了,通俗易懂. https://www.cnblogs.com/gtarcoder/p/4890739.html #include <iostream> #include <string> #include <cmath> #include <…
Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3408   Accepted: 1513 Description John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must…
题意: 从出发点到目的地往返一次,道路i连接着ai号和bi号,长度为ci.同一条路只能走一次,求最小路径长度. 分析: 如果没有往返,那么就是简单的最短路问题.如果规定严格从左到右,那么就是简单的双调旅行商问题.对于本题,同样还是将往返看成是从出发地开始的两条没有公共边的路径,便可以转化为求流量为2的最小费用流了~注意边为无向边 代码: #include<cstdio> #include<vector> #include<iostream> #include<qu…
CodeForces 429B  Working out 预处理出从四个顶点到某个位置的最大权值,再枚举相遇点,相遇的时候只有两种情况,取最优解即可. #include<iostream> #include<vector> #include<cmath> #include<map> #include<algorithm> #include<cstring> #include<cstdio> #include<cstd…
[SinGuLaRiTy-1026] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [UVA 1025] A Spy in the Metro 题目描述 特工玛利亚被送到S市执行一个特别危险的任务.她需要利用地铁完成他的任务,S市的地铁只有一条线路运行,所以并不复杂. 玛利亚有一个任务,现在的时间为0,她要从第一个站出发,并在最后一站的间谍碰头.玛利亚知道有一个强大的组织正在追踪她,她知道如果一直呆在一个车站,她会有很大的被抓的风险,躲…
Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6986   Accepted: 2901 Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beauti…
POJ 1637 Sightseeing tour 题目链接 题意:给一些有向边一些无向边,问能否把无向边定向之后确定一个欧拉回路 思路:这题的模型很的巧妙,转一个http://blog.csdn.net/pi9nc/article/details/12223693 先把有向边随意定向了,然后依据每一个点的入度出度之差,能够确定每一个点须要调整的次数,然后中间就是须要调整的边,容量为1,这样去建图最后推断从源点出发的边是否都满流就可以 代码: #include <cstdio> #includ…
POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of which contains his house and the Nth of which contains the b…
嗯,这是我上一篇文章说的那本宝典的第二题,我只想说,真TM是本宝典……做的我又痛苦又激动……(我感觉ACM的日常尽在这张表情中了) 题目链接:http://poj.org/problem?id=1637 Time Limit: 1000MS Memory Limit: 10000K Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that t…
题目:id=2135" target="_blank">poj 2135 Farm Tour 题意:给出一个无向图,问从 1 点到 n 点然后又回到一点总共的最短路. 分析:这个题目不读细致的话可能会当做最短路来做,最短路求出来的不一定是最优的,他是两条分别最短,但不一定是和最短. 我们能够用费用流来非常轻易的解决,建边容量为1,费用为边权.然后源点s连 1 .费用0 .容量 2 ,n点连接汇点,容量2,费用0,,就能够了. 注意这个题目是无向图,所以要建双向边. AC…
B - Sightseeing tour POJ - 1637 https://blog.csdn.net/qq_36551189/article/details/80905345 首先要了解一下欧拉回路的基本思路. 欧拉回路:如果是无向图,那么每一个点连的边的数量为偶数,如果是有向图,那么每一个点的入度要等于出度. 欧拉路径:这个欧拉路径是没有成环的,如果是无向图,那么除了两个点连的边是奇数,其他都是偶数, 如果是有向图,那么除了有一个点入度比出度大1,有一个点的出度比入度大1 ,其他都是入度…
Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9276   Accepted: 3924 Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beauti…
http://poj.org/problem?id=1739 题意:n×m的棋盘,'#'是障碍,'.'是空白,求左下角走到右下角且走过所有空白格子的方案数.(n,m<=8) #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; #define BIT(a,b) ((a)<<((b)<<1)) #…
Sightseeing tour   Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beautiful city. They want to construct the tour so that every street in the city is vis…
插头DP 楼教主男人八题之一! 要求从左下角走到右下角的哈密顿路径数量. 啊嘞,我只会求哈密顿回路啊……这可怎么搞…… 容易想到:要是把起点和重点直接连上就变成一条回路了……那么我们就连一下~ 我们可以在整张图下面加两行:(例:3*5) 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 红色的是原来的起点和终点,下面紫色的路径将这两个点连了起来= =然后这题瞬间就变回了Formula 1那题……求哈密顿回路数量,so easy有没有~(其实不这样加也可以做,起点…
Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8628   Accepted: 3636 Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beauti…
Farm Tour Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 2135 64-bit integer IO format: %lld      Java class name: Main   When FJ's friends visit him on the farm, he likes to show them around. His farm compr…
题目大意: 给你一个n个农场,有m条道路,起点是1号农场,终点是n号农场,现在要求从1走到n,再从n走到1,要求不走重复路径,求最短路径长度. 算法讨论: 最小费用最大流.我们可以这样建模:既然要求不能走重复路,就相当于每条边的容量是1,我们只可以单向流过容量为1的流量.但是要注意,对于每一条边来说, 它可能是去路的边,也可能是回路的边,所以这个图是个无向图.在加边的时候,两个方向的边都要加.所以要加两组的边,流量为1像正常一样加边就可以了. 然后我们考虑,求这个“环”就是相当于求从1..N的两…
Description A square township has been divided up into n*m(n rows and m columns) square plots (1<=N,M<=8),some of them are blocked, others are unblocked. The Farm is located in the lower left plot and the Market is located in the lower right plot. T…
Evacuation Plan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4914   Accepted: 1284   Special Judge Description The City has a number of municipal buildings and a number of fallout shelters that were build specially to hide municipal w…
Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6448   Accepted: 2654 Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beauti…
http://poj.org/problem?id=1637 题意:给出n个点和m条边,这些边有些是单向边,有些是双向边,判断是否能构成欧拉回路. 思路: 构成有向图欧拉回路的要求是入度=出度,无向图的要求是所有顶点的度数为偶数. 但不管是那个,顶点的度数若是奇数,那都是不能构成的. 这道题目是非常典型的混合图欧拉回路问题,对于双向边,我们先随便定个向,然后就这样先记录好每个顶点的入度和出度. 如果有顶点的度数为奇数,可以直接得出结论,是不能构成欧拉回路的. 那么,如果都是偶数呢? 因为还会存在…
题目:http://poj.org/problem?id=1637 先给无向边随便定向,如果一个点的入度大于出度,就从源点向它连 ( 入度 - 出度 / 2 ) 容量的边,意为需要流出去这么多:流出去1表示改了一条边的方向,会使自己出度-1.入度+1,所以容量要/2:出度大于入度的点类似地连向汇点:无向边按给它定的方向的反方向连上容量为1的边:最后看看能否满流即可. #include<cstdio> #include<cstring> #include<algorithm&g…
Description A square township has been divided up into n*m(n rows and m columns) square plots (1<=N,M<=8),some of them are blocked, others are unblocked. The Farm is located in the lower left plot and the Market is located in the lower right plot. T…
Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of which contains his house and the Nth of which contains the big barn. A total M (1 <= M <…
Link: POJ 1739 传送门 Solution: 这题除了一开始的预处理,基本上就是插头$dp$的模板题了 由于插头$dp$求的是$Hamilton$回路,而此题有起点和终点的限制 于是可以构造一条$[n,1]->[n+2,1]->[n+2,m]->[n,m]$的路径,正好只添加一条$S->T$的路径 接下来就是插头$dp$的模板了 推荐三篇文章,看完基本上就懂插头$dp$了吧, litble:https://blog.csdn.net/litble/article/det…
[题目链接] http://poj.org/problem?id=2135 [题目大意] 有一张无向图,求从1到n然后又回来的最短路 同一条路只能走一次 [题解] 题目等价于求从1到n的两条路,使得两条路的总长最短 那么就等价于求总流量为2的费用流 [代码] #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #i…