摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1728汉语题目 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能转太多弯了,否则她会晕倒的。我们假定给定的两个位置都是空地,初始时,gloria所面向的方向未定,她可以选择4个方向的任何一个出发 阅读全文
posted @ 2011-11-29 21:08 快乐. 阅读(478) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1253好不容易一个汉语的题目 题意就是题目了bfs代码:#include<iostream>#include<cstdio>#include<queue>using namespace std;int f,g,h,T,bx,by,bz,ex,ey,ez;int a[52][52][52];int XX[6][3]={{-1,0,0},{0,-1,0},{0,0,-1},{0,0,1},{0,1,0},{1,0,0}};struct node{int x,y,z,step;} 阅读全文
posted @ 2011-11-29 00:58 快乐. 阅读(228) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1312'.'可以走,'#'不可以走 '@'是起点 问最多走多少步就是坐标问题 弄的有点纠结 以后得养成好习惯 不然被坐标绕晕了代码(bfs版) :#include<iostream>#include<queue>#include<cstring>using namespace std;char ch[22][22];int r,c;int XX[4][2]={{-1,0},{0,-1},{0,1},{1,0}};struct 阅读全文
posted @ 2011-11-28 00:17 快乐. 阅读(229) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3107跟poj 1655差不多但是那个一下过了 这个却。。。因为addedge(u,v);错写成了 addedge[u][v]...彻底无语 泪奔啊代码:#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>const int MAX=50005;using namespace std;int visit[MAX],head[MAX],ans[MAX],num[MAX];int n,k,sizemin,sum 阅读全文
posted @ 2011-11-27 01:05 快乐. 阅读(210) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1655题意:有N个点,N-1条边生成一棵树 从中去点一个点 树就变成森林,记下森林中包含点最多的一棵树 及点的个数 求去哪个点使包含的点最少 ,叙述的不好 自己看题理解 树形dfs代码:#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int MAX=20005;int visit[MAX],num[MAX],head[MAX],ans;int n,mark,k,sum,sizemin;struct{i 阅读全文
posted @ 2011-11-26 23:04 快乐. 阅读(213) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1238字符匹配 先贴个代码#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>using namespace std;struct node{ char s[102]; int len;}a[102];int cmp(const void*a,const void*b){ return (*(node*)a).len>(*(n 阅读全文
posted @ 2011-11-25 22:16 快乐. 阅读(322) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1372象棋中给出起点到终点,马最少走几步?马走日子 ,基础的BFS代码:#include<iostream>#include<queue>#include<string>#include<cstring>#include<cstdio>using namespace std;int a[10][10], visit[10][10];int bx,by,ex,ey;int XX[8][2]={{-2,-1},{-1,-2},{1,-2},{2,-1}, 阅读全文
posted @ 2011-11-25 19:25 快乐. 阅读(229) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1072在n×m的地图上,0表示墙,1表示空地,2表示人3表示目的地,4表示有炸弹重启器。炸弹的时间是6,人走一步所需要的时间是1求人从2走到3的最短时间第一次的代码删了 这次的代码写的才舒服 贴上小庆祝一下代码:#include<iostream>#include<queue>#include<cstdio>using namespace std;int row,col,bx,by,ex,ey;int map[10][10],XX[4][2]={{-1,0},{1 阅读全文
posted @ 2011-11-24 12:00 快乐. 阅读(148) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1241BFS 横着,竖着或斜着相连都是一组 一共有几组?本来很基础的一道搜索 可是有一个地方错误 找了一晚上 while(beg<end) 错写为了 while(beg<=end) 这道题我用的BFS 还可以DFS 并查集也可以做敲了俩代码 改了一晚上 贴一下吧(一)BFS#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<queue>us 阅读全文
posted @ 2011-11-23 21:47 快乐. 阅读(241) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1240三维的BFS 但是一开始理解错题意了 哎。。。 怎么犯这种错误捏代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;char a[12][12][12];int visit[12][12][12];//行列int bx,by,bz,ex,ey,ez,step,N;int XX[6]={1,-1,0,0,0,0},YY[6]={0, 阅读全文
posted @ 2011-11-22 21:37 快乐. 阅读(212) 评论(0) 推荐(0) 编辑