HDU 6188最小费用流】的更多相关文章

题目链接:http://hdu.hustoj.com/showproblem.php?pid=6118 掉坑里了,图很好建,Wa了一发,看了Disscuss里面有人提供了一组样例,画图发现:最小流模板是在满足最大流情况下的最小费用,而本题目不需要满足最大流直接求最小费用.注意一下. /*5 41 2 1 22 1 2 12 3 4 55 4 3 2100 1 1 11 2 12 3 13 4 11 5 1*/ 应该输出8的. #include <iostream> #include <c…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意 有n个数字,每个数字小于等于n,两个相同的数字价值为1,三个连续的数字价值为1 .问这n个数字的最大价值是多少 思路 用map对这n个数字中每个数字出现的次数进行统计,用ans记录总价值.然后从数字1开始向后考虑,如果数字i出现的次数不小于2,那么ans加上数字i出现的次数除以二(两个相同的数字价值为1),然后让这个次数对2取模,接下来判断数字i还有没有(即:是否为1):如果为1,考虑数…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意:给了n个数,然后现在问我们最多构成多少个对子和顺子,其中对子是2个相同的牌,顺子是3个连续的牌. 解法:考虑贪心,我们尽量放对子,但是有一种特殊情况就是,我们可以退一个对子出来和周围的相邻点构成顺子. #include <bits/stdc++.h> using namespace std; const int maxn = 1e6+6; int cnt[maxn]; int main…
集训的图论都快结束了,我才看懂了最小费用流,惭愧啊. = = 但是今天机械键盘到了,有弄好了自行车,好高兴\(^o^)/~ 其实也不是看懂,就会套个模板而已.... 这题最重要的就是一个: 多组输入一定要写个init()函数清空,并且输入的时候每次都要调用init() #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include &…
Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others) Total Submission(s): 1120    Accepted Submission(s): 579 Problem Description There are N cities in our country, and M one-way roads connecting them. Now L…
#include <cstdio> #include <queue> #include <cstring> #include <cmath> #define mul(a) (a)*(a) using namespace std; ; ; const int inf = 0x3f3f3f3f; struct ZKW_flow{ int st, ed, ecnt, n; int head[Maxn]; int cap[Maxm], cost[Maxm], to[…
思路:这题我在下午重现的时候就用的费用流做,可是各种悲催的超时,只是我一开始的那种建图方式多了一个二分查找. 戏剧性的是,求距离的返回值写成int型了,CodeBlock编译器又没有警告,然后就WA啊WA,AC率一下就被拉低了. 当然,对每种工人分别建图是不变的,因为每种工人互不影响. 后来想到了一个较好的建图方式,将每个点拆成3个点,i,i+n,i+2*n. 1号点就是仓库,也就是超级源点,3*n+1号点为超级汇点. 由1号点想每个i建一条流量为ty[i][j],费用为1的边.表示每次增加流量…
思路:主要就是要把一个每个城市拆为两个点,建一条容量为1,费用为-inf的边,保证每个城市都会被遍历. /*最小费用最大流*/ #include<iostream> #include<cstring> #include<cstring> #include<cmath> #include<cstdio> using namespace std; ; ; struct Edge{ int v; int val; int cost; int next;…
栈. 将数字排序后,一个一个压入栈.如果栈顶两个元素形成了对子,那么$ans+1$,弹出栈顶两个元素:如果栈顶三个元素形成了顺子,那么$ans+1$,弹出栈顶三个元素. #include<bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; int n; int a[maxn]; int b[maxn]; int c[maxn]; int main() { while(~scanf("%d",…
用vis表贪心异常方便 #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=j;i<=k;i++) #define rrep(i,j,k) for(register int i=j;i>=k;i--) using namespace std; typedef long long ll; const int maxn = 1e6+11; const int N = 1e6; int num[maxn],n,q;…