poj1979】的更多相关文章

POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can mo…
题目链接 http://poj.org/problem?id=1979 思路 floodfill问题,使用dfs解决 代码 #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N = 20; char maze[N][N]; int visit[N][N]; int dir[4][2] = {{-1, 0}, {0 ,1}, {1, 0}, {0,…
POJ2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25366   Accepted: 12778 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <=…
题目链接:pid=1312" target="_blank">HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9902    Accepted Submission(s): 6158 Pro…
题目在这里 题目意思是这样的,一个人起始位置在    '@'  处,他在途中能到达的地方为 ' .  '     而  '#' 是障碍物,他不能到达. 问途中他所有能到达的   '.'的数量是多少 ??当然,他自己本身也算一个能到达的点. 其中两个样例的结果是这样的走出来的,这是"显而易见"的,哈哈-当然,当图很大的时候,数起来就能费事了. 所用的这个方法叫做FlooFill(洪水覆盖),从它名字来看就是个很暴力直接的方法,只要我能到的地方,我都用水把你淹没了.可以联想一下,在田地里用…
题目链接:http://poj.org/problem?id=1979 深度优先搜索非递归写法 #include <cstdio> #include <stack> using namespace std; , MAX_H = ; ]; int W, H; int DFS(int sx, int sy); int main() { && W != && H != ) { ; i < W; i++) scanf("%s", M…
速刷一道DFS Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can mo…
#include<stdio.h>int map[4][4]={'.','.','.','.',      '#','.','.','.',      '.','#','.','.',      '#','.','.','@'};int mov1[4]={0,0,1,-1};int mov2[4]={1,-1,0,0};typedef struct node{ int x; int y;}node;node dui[100];int tou=0;int wei=1;void bfs(){ in…
Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 47466   Accepted: 25523 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a…
Time limit1000 ms Memory limit30000 kB There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on r…
挑战习题搜索-1 题意: 给定起点,然后求一个可以到达的数量,位置"."都可以走.每次应该是上下左右都可以走. 思路: 这题应该DFS更好写,但是BFS也可以写吧. 好久没写了- dfs挫代码--.. #include<cstdio> #include<iostream> #include<math.h> #include<string.h> #include<algorithm> using namespace std; #…
http://poj.org/problem?id=1979 基础搜索. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <string> #include <set>…
  深度优先搜索DFS,从最开始状态出发,遍历一种状态到底,再回溯搜索第二种. 题目:POJ2386  思路:(⊙v⊙)嗯  和例题同理啊,从@开始,搜索到所有可以走到的地方,把那里改为一个值(@或者真值什么的),最后遍历一遍地图就好了. /* input: 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 表示有13个可以走到的地方(包括原来那一格).*/ #include <stdio.h> ][]; void solv…
深度优先搜索(depth-first search)是对先序遍历(preorder traversal)的推广.”深度优先搜索“,顾名思义就是尽可能深的搜索一个图.想象你是身处一个迷宫的入口,迷宫中的路每一个拐点有一盏灯是亮着的,你的任务是将所有灯熄灭,按照DFS的做法如下: 1. 熄灭你当前所在的拐点的灯 2. 任选一条路向前(深处)走,每经过一个拐点将灯熄灭直到与之相邻的拐点的灯全部熄灭后,原路返回到某个拐点的相邻拐点灯是亮着的,走到灯亮的拐点,重复执行步骤1 3. 当所有灯熄灭时,结束 将…
深度优先搜索(DFS) 往往利用递归函数实现(隐式地使用栈). 深度优先从最开始的状态出发,遍历所有可以到达的状态.由此可以对所有的状态进行操作,或列举出所有的状态. 1.poj2386 Lake Couting 题意:八连通被认为连接在一起,求总共有多少个水洼? Sample Input: 10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.…
1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood Species POJ 2418D - StationE - Web Navigation ZOJ 1061F - Argus ZOJ 2212G - Plug-in2.SegmentTreeA-敌兵布阵 hdu 1166B - I Hate It HDU 1754C - A Simple Pro…
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 POJ1016 POJ1017 POJ1169 POJ1298 POJ1326 POJ1350 POJ1363 POJ1676 POJ1786 POJ1791 POJ1835 POJ1970 POJ2317 POJ2325 POJ2390 POJ1012 POJ1082 POJ1099 POJ1114…
Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has a di…
-->Red and Black Descriptions: 有个铺满方形瓷砖的矩形房间,每块瓷砖的颜色非红即黑.某人在一块砖上,他可以移动到相邻的四块砖上.但他只能走黑砖,不能走红砖. 敲个程序统计一下这样可以走到几块红砖上. Input  多组测试用例.每组数组开头有两个正整数W和H:W与H分别表示 x- 与 y- 方向上瓷砖的数量.W和W均不超过20. 还有H行数据,每行包含W个字符.每个字符表示各色瓷砖如下. '.' - 一块黑砖 '#' - 一块红砖 '@' - 一个黑砖上的人(一组数…
DFS作为一个竞赛必学的一个知识点,怎么说我都得写一下 遍历就相当于爆搜,只不过是搜的方式比较规整罢了. 深度优先遍历:为了避免重复访问某个顶点,可以设一个标志数组vis[i],未访问时值为0,访问一次后就改为1.       代码实现: //DFS参考代码 #include <cstdio> const int maxn=1010; int a[maxn][maxn]; int vis[maxn]; int n,m; void dfs(int u){ printf("%d\n&qu…