摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2444思路:首先要判断能否构成二分图,用bfs对当前点u染色,对u的邻接点v的颜色进行判断,如果为染色,则染色后入队列,否则,判断color[v]==color[u],如果相等,说明无法构成二部图 ,直接返回false即可。最后就是简单的匈牙利直接求最大匹配就可以了,不过这儿是无向图,最后要除以2。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm 阅读全文
posted @ 2013-06-03 21:23 ihge2k 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2376思路:引:如果暴力枚举两点再求距离是显然会超时的。转换一下思路,我们可以对每条边,求所有可能的路径经过此边的次数:设这条边两端的点数分别为A和B,那 么这条边被经过的次数就是A*B,它对总的距离和的贡献就是(A*B*此边长度)。我们把所有边的贡献求总和,再除以总路径数N*(N-1)/2,即为最 后所求。每条边两端的点数的计算,实际上是可以用一次dfs解决的。任取一点为根,在dfs的过程中,对每个点k记录其子树包含的点数(包括其自身),设点数为a[k],则k的父亲一侧的点数即为N-a[k]。这个 阅读全文
posted @ 2013-06-03 20:12 ihge2k 阅读(2068) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4324思路:dfs搜索即可,如果当前点u的下一个点v已经访问过了,那么就判断dist[u]==dist[[v]+2,成立返回true,否则更新dist[v]=dist[u]+1,继续深搜。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 # 阅读全文
posted @ 2013-06-03 17:08 ihge2k 阅读(293) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2354思路:初始化step[][]==inf,然后如果当前点p.step<step[p.x][p.y],则入优先队列。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 #define inf 1<<30 8 struct N 阅读全文
posted @ 2013-06-03 11:09 ihge2k 阅读(645) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2819思路:有矛盾关系的可以考虑二分匹配= =只交换行或者只交换列都能得到目的,如果不能,就输出-1。建图的时候应该建有向图。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath>[ 6 using namespace std; 7 #define MAXN 111 8 int n,x; 9 in 阅读全文
posted @ 2013-06-03 09:51 ihge2k 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2831思路:按剩余时间排序即可,简单贪心。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 111 7 struct Node{ 8 int v,d,index; 9 }node[MAXN];10 int n,t;11 bool flag;12 13 int cm 阅读全文
posted @ 2013-06-03 08:46 ihge2k 阅读(175) 评论(0) 推荐(0) 编辑