The citizens of a small village are tired of being the only inhabitants around without a connection to the Internet. After nominating the future network administrator, his house was connected to the global network. All users that want to have access…
NETADMIN - Smart Network Administrator #max-flow The citizens of a small village are tired of being the only inhabitants around without a connection to the Internet. After nominating the future network administrator, his house was connected to the gl…
题目大意:一座村庄有N户人家.只有第一家可以连上互联网,其他人家要想上网必须拉一根缆线通过若干条街道连到第一家.每一根完整的缆线只能有一种颜色.网管有一个要求,各条街道内不同人家的缆线必须不同色,且总的不同颜色种数最小.求在指定的K户人家都能上网的前提下,最小的不同颜色种数.(1 <= N <= 500) 题解:上来看到颜色就不知道怎么下手了...那么我们不妨就枚举颜色好了:先按照题意建模,再对于每一个街道限一下我们枚举的颜色就好了,如果最大流小了说明不行,如果正好等于k就说明可以.那么不难看…
The citizens of a small village are tired of being the only inhabitants around without a connection to the Internet. After nominating the future network administrator, his house was connected to the global network. All users that want to have access…
1305: [CQOI2009]dance跳舞 题目:传送门 题解: 一眼网络流基础建模...然后就GG了 二分答案+拆点建边+最大流判断: 把男女生拆为男1,男2,女1,女2 1.男1和男2还有女1和女2之间连边,流量为约束条件k 2.st连男1,女2连ed,流量为二分的mid 3.如果男生i喜欢女生j,就将男1与女2相连(不在约束条件内) 4.如果不喜欢,就将男2与女1相连(在约束条件内) 代码: #include<cstdio> #include<cstring> #incl…
在spoj上用题号找题就已经是手动二分了吧 把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流是否等于k来调整上下界. #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int N=505,inf=1e9; in…
题目大概是说,一个村庄有n间房子,房子间有m条双向路相连.1号房子有网络,有k间房子要通过与1号房子相连联网,且一条路上不能有同样颜色的线缆,问最少要用几种颜色的线缆. 二分枚举颜色个数,建立容量网络跑最大流判断解是否成立:源点是1,所有要联网的房子向汇点连容量1的边,所有双向边改为容量为枚举的解的边,如果最大流等于k那这个解就成立. 注意重边.. #include<cstdio> #include<cstring> #include<queue> #include&l…
传送门[洛谷] 常见套路? 关键点连新建汇点 流量1 源点1 原图中的边 二分流量. 二分+判满流 做完了. 附代码. #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #define inf 20021225 #define ll long long #define mxm 251000 #define mxn 510 u…
Code: #include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) freopen(s".in","r",stdin) #define maxn 1000000 #define ll long long using namespace std; char str[maxn]; int arr[maxn],pos[maxn],x[maxn]…
[题目链接] http://www.spoj.pl/problems/PHRASES/ [题目大意] 求在每个字符串中出现至少两次的最长的子串 [题解] 注意到这么几个关键点:最长,至少两次,每个字符串. 首先对于最长这个条件,我们可以想到二分答案, 然后利用后缀数组所求得的三个数组判断是否满足条件. 其次是出现两次,每次出现这个条件的时候, 我们就应该要想到这是最大值最小值可以处理的, 将出现在同一个字符串中的每个相同字符串的起始位置保存下来, 如果最小值和最大值的差距超过二分长度L,则表明在…