上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 30 下一页
摘要: 题意:一个连通无向图,问你增加一条边后,让原图桥边最少 分析:先边双缩点,因为连通,所以消环变树,每一个树边都是桥,现在让你增加一条边,让桥变少(即形成环) 所以我们选择一条树上最长的路径,连接两端,这样减少的桥边,最多,所以就是求树的直径 注:这题有重边,所以边双缩点也需要用重边版的 #inclu 阅读全文
posted @ 2016-05-13 15:41 shuguangzw 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 分析:边双缩点后,消环变树,然后答案就是所有叶子结点(即度为1的点)相连,为(sum+1)/2; 注:此题有坑,踩踩更健康,普通边双缩短默认没有无向图没有重边,但是这道题是有的 我们看,low数组是我们缩点的关键,记录最早的前驱,但是不能由父边过来,这是因为没有重边 当有重边时,父边也可以更新low 阅读全文
posted @ 2016-05-13 14:49 shuguangzw 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <vector> #include <stack> u 阅读全文
posted @ 2016-05-13 13:46 shuguangzw 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 模板题,注意输出 #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <vector> #include <stack> using namespace std; typedef 阅读全文
posted @ 2016-05-12 23:43 shuguangzw 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 参考这篇博客: http://blog.csdn.net/ascii991/article/details/7466278 #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include < 阅读全文
posted @ 2016-05-12 22:59 shuguangzw 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 题解上说的很清楚了,我照着写的,表示膜拜题解 然后时间复杂度我觉得应该是O(nlogn),虽然常数略大,预处理和倒着扫,都是O(nlogn) #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> # 阅读全文
posted @ 2016-05-12 18:34 shuguangzw 阅读(472) 评论(0) 推荐(0) 编辑
摘要: 感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; typedef pair<double,int>pii; const int 阅读全文
posted @ 2016-05-12 14:09 shuguangzw 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 题意:有n个人,每个人a[i]个物品,进行k次操作,每次都从最富有的人手里拿走一个物品给最穷的人 问k次操作以后,物品最多的人和物品最少的人相差几个物品 分析:如果次数足够多的话,最后的肯定在平均值上下,小的最多被补到sum/n,大最多减少到sum/n,或者sum/n+1 然后就二分最小值,看所有小 阅读全文
posted @ 2016-05-12 14:08 shuguangzw 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 分析:建一个远点,往每个点连建井的价值(单向边),其它输水线按照题意建单向边 然后以源点为根的权值最小的有向树就是答案,套最小树形图模板 #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #in 阅读全文
posted @ 2016-05-10 23:34 shuguangzw 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 这个题就是需要求整个有向带权图的最小树形图,没有指定根,那就需要加一个虚根 这个虚根到每个点的权值是总权值+1,然后就可以求了,如果求出来的权值大于等于二倍的总权值,就无解 有解的情况,还需要输出最根,多解的情况,肯定是某个环上所有的点为根都可以(比如所有的点构成一个环), 这样加边的时候虚边的时候 阅读全文
posted @ 2016-05-10 22:31 shuguangzw 阅读(165) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 30 下一页