摘要: 链接:http://poj.org/problem?id=1655题意: 求树的重心;树的重心为去掉该节点使其形成的森林中的树的最大的节点数最小;思路:对于一棵树的任意一个节点做一次DFS就能遍历整棵树, 去掉某节点时, 遍历其子树的节点个数,和为sum那么另一个子树的节点为N-sum-1;View Code 1 #include <cstdio> 2 #include <cstring> 3 const int M=20005; 4 int T, N, t, ans, r, x, y; 5 int h[M*2], sum[M*2];// re[M*2]; 6 stru 阅读全文
posted @ 2013-01-07 20:19 淡墨æ末央 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=1088题意: 中文题;思路:暴力每一个点作为起点DFS; 对于每个点比较其四周的点比较View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <stdlib.h> 6 #include <cmath> 7 using namespace std; 8 int N, M; 9 struct Node 10 {11 i 阅读全文
posted @ 2013-01-07 14:39 淡墨æ末央 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=1063题意:把若干个白球和黑球围成一圈,每个球都可以与与它距离为2的球交换位置,判断能否把黑球和白球分开;思路:白球和黑球分开最后的结果为把球排成一排后所有白球或者黑球在奇数位上的个数和在偶数位上的个数之差为2以内(不等于2),若总数为奇数,则不管小球的布局如何,一定能使黑白球各自连续。因为在这种情况下,奇位置上的小球通过交换可以移动到偶位置上。而若总数为偶数则需要满足以上要求了,因为为偶数时它们交换相对奇偶性不变.View Code 1 #include <iostream> 2 #include <cstdio& 阅读全文
posted @ 2013-01-07 09:33 淡墨æ末央 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=1050题意:求给定的矩阵的最大子矩阵和;思路:将二维转化为一维求最大连续子串和;母串为从原矩阵中截取连续的几行,求其最大子串和;View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <cmath> 6 using namespace std; 7 8 int N, a[105][105], s[105]; 9 10 int 阅读全文
posted @ 2013-01-07 08:50 淡墨æ末央 阅读(137) 评论(0) 推荐(0) 编辑