2011年7月28日
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1272方法一:当你输入的x,y的根节点fx,fy相同时,说明已经可达,再连接就是有多余一条路径了。迷宫应该只有一个集合,多余一个就不符合。当直接输入00时,直接输出yes代码:View Code 1 #include<stdio.h> 2 int father[100001]; 3 bool visit[100001]; 4 int find(int x) 5 { 6 while(x!=father[x]) 7 x=father[x]; 8 return x; 9 }10 11 int ma 阅读全文
posted @ 2011-07-28 10:21 渲染独白 阅读(267) 评论(1) 推荐(0) 编辑
2011年7月27日
摘要: 题目:http://poj.org/problem?id=2446本题和hdu1507类似,具体解释:http://www.cnblogs.com/lujiacheng/archive/2011/07/25/2116247.html代码:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define maxn 51 4 int dx[]={-1,1,0,0}; 5 int dy[]={0,0,-1,1}; 6 7 int n,m,k,ans; 8 int a[maxn][maxn],mark[maxn*maxn] 阅读全文
posted @ 2011-07-27 10:38 渲染独白 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=2594最小路径覆盖, 要求每个点只经过一次。此题说明一个点可以经过无数次。。那么.....刚开始看到。。。狂wa当数据为5 41 22 34 22 5时,求匹配时在用到4之前,2已经被匹配了,4这里就找不到匹配的了,4和5也就成孤立点了用最最小路径求的1-》2-》3后,2就被删除了,4和5就连不起来了,所以用floyd求某两点之间是否可达..然后用新图求最小路径覆盖.....代码:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define maxn 阅读全文
posted @ 2011-07-27 09:46 渲染独白 阅读(132) 评论(0) 推荐(0) 编辑
2011年7月26日
摘要: 题目:http://poj.org/problem?id=1719要求每一行必须都被射到,每一列恰好一个格子被射到。通过行r去求匹配数num当r<=c时,num是可以等于r的这时候每一行都被射到过,可能存在列没有被射到,可以再该列中任意选一个格子,因为对于每一行中被射中的格子数没有限定当r>c时,num不可能等于r也就是说不是所有行都可以被射到,所以不符合要求,直接输出no代码:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define maxn 1001 4 int r,c,n; 5 int m 阅读全文
posted @ 2011-07-26 19:04 渲染独白 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=2724相差一位的可以同时删除,所以就剩下一次,只要求出相差一位的有多少对,用总数减去就可以了。同时,两个数中1的个数都是偶数或奇数个的话,那么不可能相差一位,所以根据1的个数可以分成两组。判断是否相差一位用位运算代码:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define maxn 1024 4 5 int n,m,l,r; 6 int left[maxn],right[maxn],mark[maxn]; 7 bool visit[maxn],m 阅读全文
posted @ 2011-07-26 15:22 渲染独白 阅读(212) 评论(0) 推荐(0) 编辑
2011年7月25日
摘要: 题目:http://poj.org/problem?id=2584代码:View Code 1 #include<stdio.h> 2 #include<string.h> 3 int n,m,mark[201],num[201],start[201],end[201]; 4 bool map[201][201],visit[201]; 5 6 7 void get_map() 8 { 9 int i,j,k;10 char s[12];11 scanf("%d",&n);12 for(i=0;i<n;i++)13 {14 scanf( 阅读全文
posted @ 2011-07-25 22:18 渲染独白 阅读(177) 评论(1) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1507题目有指出 ( (N x M) - K <= 50), 所以最多也就 50 个点. 然后遍历图上每一个可行点点, 把它和他 上下左右的可行点连边, 最后就得到了一个二分图, 然后直接最大匹配, 不过结果有问题, 分析不透彻, 出现了重边. 再 分析下, 因为相邻块之间的下标和存在奇偶关系, 所以只取 偶数 或 奇数点 建图就行了.View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 #define maxn 11 阅读全文
posted @ 2011-07-25 15:29 渲染独白 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1498这题想了很久都没想到,看了下别人的分析,才恍然大悟,其实就是一个棋盘问题。用最少的棋子去覆盖整个棋盘。而这里是通过行列来覆盖,和车的走位一样,所以只要求每种颜色的匹配数,如果大于k就说明不能全部踩破。方法一:将颜色从1——max枚举。代码:View Code #include<stdio.h>#include<string.h>int n,color[101][101],mark[101],ans[51];bool map[101][101],visit[101];void 阅读全文
posted @ 2011-07-25 09:59 渲染独白 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=2236方法一:修好的电脑用k[i]=1标记,没有修好的用k[i]=0标记,构造并查集时用k[i]=1的代码:View Code #include<stdio.h>#include<math.h>struct node{ int x,y;}s[1001];int d;int set[1001];bool k[1001];int distance(node a,node b){ if((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)<=d) return 1; return 0; 阅读全文
posted @ 2011-07-25 08:53 渲染独白 阅读(213) 评论(0) 推荐(0) 编辑
2011年7月22日
摘要: 题目:http://poj.org/problem?id=1611求包括0号的集合的集合元素个数。方法一:用一个num数组计算第i个集合中的元素的个数View Code #include<stdio.h>#define maxn 30001int num[maxn],father[maxn];int flag;int find(int x){ int r=x; if(father[r]!=r) r=find(father[r]); int j,i=x; while(r!=i) { j=father[i]; father[i]=r; i=j; } return r;}void mer 阅读全文
posted @ 2011-07-22 15:20 渲染独白 阅读(145) 评论(0) 推荐(0) 编辑