Poj(2135),MCMF,模板】的更多相关文章

题目大意: 给你一个n个农场,有m条道路,起点是1号农场,终点是n号农场,现在要求从1走到n,再从n走到1,要求不走重复路径,求最短路径长度. 算法讨论: 最小费用最大流.我们可以这样建模:既然要求不能走重复路,就相当于每条边的容量是1,我们只可以单向流过容量为1的流量.但是要注意,对于每一条边来说, 它可能是去路的边,也可能是回路的边,所以这个图是个无向图.在加边的时候,两个方向的边都要加.所以要加两组的边,流量为1像正常一样加边就可以了. 然后我们考虑,求这个“环”就是相当于求从1..N的两…
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…
题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=2715 Time limit : 5 sec Memory limit : 64 M Zhouguyue is a "驴友" and nowadays he likes traveling on an N * N matrix with a non-negative number in each grid, and each grid has a height. Zhouguyue star…
Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #define ll long lo…
题目:id=2135" target="_blank">poj 2135 Farm Tour 题意:给出一个无向图,问从 1 点到 n 点然后又回到一点总共的最短路. 分析:这个题目不读细致的话可能会当做最短路来做,最短路求出来的不一定是最优的,他是两条分别最短,但不一定是和最短. 我们能够用费用流来非常轻易的解决,建边容量为1,费用为边权.然后源点s连 1 .费用0 .容量 2 ,n点连接汇点,容量2,费用0,,就能够了. 注意这个题目是无向图,所以要建双向边. AC…
题目链接:http://poj.org/problem?id=2135 Farm Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14821   Accepted: 5657 Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000…
题目链接:http://poj.org/problem?id=2195 Time Limit: 1000MS Memory Limit: 65536K Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent…
题目大意: 给定一个n个点m条边的无向图 求从点1去点n再从点n回点1的不重叠(同一条边不能走两次)的最短路 挑战P239 求去和回的两条最短路很难保证不重叠 直接当做是由1去n的两条不重叠的最短路 这样就变成了由1去n流量为2的最小费用流 #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; ; int n,m; struct EDGE { int v,w,c,r; }; vector <EDGE>…
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…
题目链接:http://poj.org/problem?id=2135 今天学习最小费用流.模板手敲了一遍. 产生了一个新的问题:对于一条无向边,这样修改了正向边容量后,反向边不用管吗? 后来想了想,得出了个结论.路径所选的边只会包括正反中的一条. #include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <queue> #include…
http://poj.org/problem?id=1459 嗯,网络流模板...多源点多汇点的图,超级汇点连发电厂,用户连接超级汇点 Status Accepted Time 391ms Memory 1588kB Length 2166 Lang G++ Submitted 2018-05-23 14:43:22 Shared RemoteRunId 18625420 #include <iostream> #include <string.h> #include <cm…
hdu 2544  求点1到点n的最短路  无向图 Sample Input2 1 //结点数 边数1 2 3 //u v w3 31 2 52 3 53 1 20 0 Sample Output32 堆优化Dijstra模板 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include &…
最后撸一发splay. 之前用treap撸的,现在splay也找到感觉了,果然不同凡响,两者之间差别与精妙之处各有其精髓! 真心赞一个! POJ平衡树的题目还是比较少,只能挑之前做过的捏一捏.但是收获很多,这一天做的题都是有一定普遍性的. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include…
标准大白书式模板 #include<stdio.h> //大概这么多头文件昂 #include<string.h> #include<vector> #include<queue> #include<algorithm> using namespace std; +; //最大点数 const int INF=0x3f3f3f3f; struct edge{ //边:起点.终点.容量.流量.单位费用 int from,to,c,f,cost; e…
[题目链接] http://poj.org/problem?id=2135 [题目大意] 有一张无向图,求从1到n然后又回来的最短路 同一条路只能走一次 [题解] 题目等价于求从1到n的两条路,使得两条路的总长最短 那么就等价于求总流量为2的费用流 [代码] #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #i…
POJ 最小生成树模板 Kruskal算法 #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #include<limits.h> #include<math.h> #include<queue> #include<st…
第一道费用流的题目--- 其实---还是不是很懂,只知道沿着最短路找增广路 建图 源点到1连一条容量为2(因为要来回),费用为0的边 n到汇点连一条容量为2,费用为0的边 另外的就是题目中输入的了 另外这题是无向边----- maxn 开到1000会re---- 存个模板先吧------------------------------------------ #include<cstdio> #include<cstring> #include<cmath> #incl…
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41051   Accepted: 16547 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a mem…
题意:给一个无向图,FJ要从1号点出发到达n号点,再返回到1号点,但是路一旦走过了就会销毁(即回去不能经过),每条路长度不同,那么完成这趟旅行要走多长的路?(注:会有重边,点号无序,无向图!) 思路: 有重边,要用邻接表.所给的每条边都要变成4条有向边!否则可能一开始就到达不了终点了.最后要再加上一个源点和汇点,容量cap(源点,1)=2,指定只能走两次,再规定其他所给的边的容量是1就行了,当边被走过了,就自动增加了流,也就走不了了. 解释看代码更清晰. //#pragma comment(li…
题目大意:有一个无向图..农夫从1号点出发..要到达N号点..然后回到1号点..来回不能走相同的路径..问最短的距离是多少. 题解:又是不能走重复路径!基本图论算法直接扔掉上网络流.不能相同就边限1,然后就MCMF就行. 然后注意:MCMF无向边是要老老实实加两次的,不能向最大流一样偷偷换掉反向弧.…
题目链接 给一个图, N个点, m条边, 每条边有权值, 从1走到n, 然后从n走到1, 一条路不能走两次,求最短路径. 如果(u, v)之间有边, 那么加边(u, v, 1, val), (v, u, 1, val), val是路的长度,代表费用, 1是流量. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm&g…
给出三个半平面交的裸题. 不会的上百度上谷(gu)歌(gou)一下. 毕竟学长的语文是体育老师教的.(卡格玩笑,别当真.) 这种东西明白就好,代码可以当模板. //poj1474 Video Surveillance //点集默认顺时针 //算法参考:http://www.cnblogs.com/huangxf/p/4067763.html #include<cstdio> #include<cmath> using namespace std; ; struct point{ d…
题意: 人回家,一步一块钱,有x个人,y个房子,求能回家的最大人数且使之费用最小 解析: 就是....套模板,,,, 建图(⊙﹏⊙)...要仔细观察呐 对于人拆不拆都可以  都能过,,,,这里贴上拆开的代码.... #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include <queue>…
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…
题目链接:http://poj.org/problem?id=3368 题意:给出n个数和Q个询问(l,r),对于每个询问求出(l,r)之间连续出现次数最多的次数. 求解RMQ问题的算法有:搜索(比较暴力),线段树,ST算法(DP),其中较为高效的是ST算法,比较常用, 复杂度:预处理O(nlogn),查询O(1). RMQ算法(ST)请参考:http://blog.csdn.net/liang5630/article/details/7917702 分析:将原序列转换一下,if(num[i]=…
Farm Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19207   Accepted: 7441 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…
题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<queue> #include<stack&…
两条路不能有重边,既每条边的容量是1.求流量为2的最小费用即可. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include…
n个点 m条边 给m条边 求1->n n->1 最小花费,每条边最多走一次 两个最短路显然不行 会影响另外一条 #include<stdio.h> #include<algorithm> #include<string.h> #include<queue> #include<math.h> using namespace std; #define inf 100000000 #define MAXN 50000 #define MAX…
题意: 有n个点和m条边,让你从1出发到n再从n回到1,不要求所有点都要经过,但是每条边只能走一次.边是无向边. 问最短的行走距离多少. 一开始看这题还没搞费用流,后来搞了搞再回来看,想了想建图不是很难,因为要保证每条边只能走一次,那么我们把边拆为两个点,一个起点和终点,容量是1,权重是这条路的长度.然后两个端点分别向起点连接容量是1权重是0的边,终点分别向两个端点连容量是1权重是0的边,从源点到1连容量为2权重为0的边,从n到汇点连容量为2权重为0的边. #include<stdio.h>…