随笔分类 - 算法--图论
摘要:题目大意: 一个无向图中,使用黑白两种颜色对顶点着色,要求相邻顶点不能同时为黑色,求最大能染黑色顶点数量以及对应顶点。解题思路: 相邻顶点间有边相连,模型转换成求 无向图 最大独立集。因为是NP问题,目前没有有效算法。 又 最大团顶点数量 = 补图的最大独立集 所以我们可以用 优化的 Bron-Kerbosch算求其补图的最大团,然后得出当前图的最大独立集View Code #include<cstdio>#include<cstring>#define N 1010bool flag[N], a[N][N];int ans, cnt[N], group[N], n,
阅读全文
摘要:题目大意: 有K个挤奶器,C头奶牛,每个挤奶器最多能给M头奶牛挤奶。求使C头奶牛头奶牛需要走的路程的最大路程最小。解题思路: 使用Floy预先求出任意两点间最短距离,然后二分枚举最大距离. 构图方案: 源点与奶牛连边,容量为1, 挤奶器与汇点连边,容量为M, 奶牛与挤奶器连边 (注意,这里只有单项边) 还要注意的是,因为预先求过最短路,初始化的时候对于0的边,赋值的无穷大不要设的太大,不然会溢出.参考代码: SAP(shortest augment path) 间隙优化, AC时间 110ms View Code #include<stdio.h>#include<stdli
阅读全文
摘要:解题思路: 源点为1,汇点为N, 直接求最大流就好View Code #include<stdio.h>#include<string.h>#include<string.h>#define MIN(a,b) (a)<(b)?(a):(b)const int inf = ~0u>>1;const int MAXN = 210;int n, m, S, T, N;int head[MAXN], idx, h[MAXN], vh[MAXN];struct Edge{ int v, f, nxt; }edge[MAXN<<4];voi
阅读全文
摘要:PIGSTime Limit:1000MSMemory Limit:10000KTotal Submissions:12924Accepted:5721DescriptionMirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the keys. Customers come to the farm one after another. Each of them has keys to s
阅读全文
摘要:1017: Fast TransportationTime Limit:10 SecMemory Limit:128 MBSubmit:72Solved:11DescriptionI’m working for a huge transportation company, and this month we get a job that deliver K important medicinal machines from city S to city T. Since the machines is so large that for each machine we should use a
阅读全文
摘要:Power NetworkTime Limit:2000MSMemory Limit:32768KTotal Submissions:19147Accepted:10099DescriptionA power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 &l
阅读全文
摘要:C. Text Editortime limit per test1 secondmemory limit per test256 megabytesVasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer
阅读全文
摘要:1014: Dice Dice DiceTime Limit:10 SecMemory Limit:128 MBDescriptionThere are 1111 ways in which five 6-sided dice (sides numbered 1 to 6) can be rolled so that the top three numbers sum to 15. Some examples are:D1,D2,D3,D4,D5 = 4,3,6,3,5D1,D2,D3,D4,D5 = 4,3,3,5,6D1,D2,D3,D4,D5 = 3,3,3,6,6D1,D2,D3,D4
阅读全文

浙公网安备 33010602011771号