I - Red and Black DFS】的更多相关文章

Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6762 Accepted Submission(s): 4284 Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit…
Red and Black Problem DescriptionThere 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 til…
题目描述 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 move only on blac…
Problem 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…
Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19731    Accepted Submission(s): 11991 Problem Description There is a rectangular room, covered with square tiles. Each tile is col…
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 move only on black til…
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 move only on black til…
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; const int maxn = 21; bool vis[maxn][maxn]; char maz[maxn][maxn]; int n,m; const int dx[4] = {1,-1,0,0}; const int dy[4] = {0,0,1,-1}; int ans; bool in(int…
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往四个方向搜索,会重复搜索,所以使用vis表来标记访问过的点,避免重复搜索. 代码如下: #include <iostream> using namespace std; ; int vis[MAX_N][MAX_N]; char map[MAX_N][MAX_N]; int red_count,…
题目链接 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,…