上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 61 下一页
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1526思路:floyd求传递闭包,然后就是最大匹配了,不过一开始输入没看清,被坑了将近2个小时。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 #define MAXN 111 8 vector<int>vet[MAXN]; 阅读全文
posted @ 2013-06-18 04:56 ihge2k 阅读(265) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669思路:由于要求minimize the size of the largest group,由此我们想到二分枚举,然后每一次求一下多重匹配就可以了。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAXN 1010 8 #define MAXM 555 9 vectorvet[MAXN];10 bool map[MAXN][MAXN];11 int Link[MAX 阅读全文
posted @ 2013-06-18 02:55 ihge2k 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389思路:纯裸的一个最大匹配题,不过悲摧的是以前一直用的dfs版一直过不了,TLE无数次啊,然后改成bfs就过了。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 #include<cmath> 7 #include<queue> 8 using namesp 阅读全文
posted @ 2013-06-18 01:51 ihge2k 阅读(268) 评论(0) 推荐(1) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边,使得这个图成为二分图。注意到n不是很大,于是我们可以想到二进制枚举,枚举每条边的两个顶点是否在同一个集合中,若是,则删除这条边。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define inf 1 >map; 9 int n,m;10 11 int main()12 {13 阅读全文
posted @ 2013-06-18 00:51 ihge2k 阅读(619) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3360思路:最小覆盖==最大匹配。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 #define MAXN 3333 8 vector<int>vet[MAXN]; 9 int map[MAXN][MAXN];10 int l 阅读全文
posted @ 2013-06-16 12:22 ihge2k 阅读(296) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4179思路:不知道怎么回事,wa了n多次,然后不知道怎么回事就过了==,还是简单的说一下思路吧:一次以起点为源点跑一遍spfa,然后以终点为起点跑一次spfa,这样我们就可以枚举difficult为maxdist的边了,设该边的端点为x,y,于是有ans=min(ans,dist1[x]+Get_Dist(x,y)+dist2[y])。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #i 阅读全文
posted @ 2013-06-13 15:34 ihge2k 阅读(443) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2065思路:递推:dp[len][0]表示长度为len的全部合法字符串的个数;dp[len][1]表示长度为len的,仅有A出现奇数次的字符串的个数;dp[len][2]表示长度为len的,仅有C出现奇数次的字符串的个数;dp[len][3]表示长度为len的,A,C均出现奇数次的字符串的个数。于是我们可以得到下列方程:dp[len][0]=2*dp[len-1][0]+dp[len-1][1]+dp[len-1][2];dp[len][1]=dp[len-1][0]+2*dp[len-1][1]+ 阅读全文
posted @ 2013-06-11 00:15 ihge2k 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 并查集一类的题目最近也做了许多,相对来说,还是比较容易理解和实现的。最早开始接触并查集是在学习用kruskal求最小生成树的时候,后来接触的题目多了,发现并查集还有好多用途,比如典型的判环,区间问题等等。学习并查集的过程中我发现,并查集的路径压缩十分重要,有时候对于题目限定的条件,在路径压缩的过程中常常伴随着节点信息的更新。有一类带权并查集的题目,往往还要开多个数组来记录节点的信息,而这些节点信息的更新就体现在路径压缩和集合合并中了。要深刻理解的话还得在多多实践。下面附上一些hdoj上的并查集习题:http://www.cnblogs.com/wally/tag/%E5%B9%B6%E6%9F 阅读全文
posted @ 2013-06-10 21:57 ihge2k 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4424题意:给你一颗树,树中每条边有一权值c,对于从i节点到j节点的路径,其权值定义为该路径上边权值的最小值,于是问找到一个中心点,使得从该点到其他节点的路径权值和最大,求该最大值。思路;要使得权值和最大,容易想到对边进行从大到小排序,用一个sum来记录权值,cnt来记录节点个数,然后每次合并时取权值和较大的那个即可。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include< 阅读全文
posted @ 2013-06-10 21:32 ihge2k 阅读(514) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4253思路:求最小生成树是显然的,题目还多了一个限制条件,就是属于A公司的边必须有K条,于是我们可以二分来实现这个目的,找一个尽量大的mid,用A公司的每条边都加上这个mid,使得求出的最小生成树中包含A公司的边至少K条,于是花费ans=sum-K*mid。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespac 阅读全文
posted @ 2013-06-10 20:02 ihge2k 阅读(409) 评论(1) 推荐(0) 编辑
上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 61 下一页