ural 1033. Labyrinth(dfs)
来源:互联网 发布:数据成熟度模型 编辑:程序博客网 时间:2024/05/21 09:23
题目链接http://acm.timus.ru/problem.aspx?space=1&num=1033
唯一注意的就是当图不连通时两个角都要搜索,搜索的总和才是最终答案。
#include <iostream>#include <cstdio>#include <cstring>int n, num;char map[34][34];bool visited[34][34] = {0};int dir[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}};void dfs(int x, int y){ if ((x==0 && y>0 && y<n-1) || (y==0 && x>0 && x<n-1) || (x==n-1 && y>0 && y<n-1) || (y==n-1 && x>0 && x<n-1)) //边上非角的墙 ++num; if ((x==0 && y==n-1) || (y==0 && x==n-1)) //两个角的需要两张 num += 2; visited[x][y] = 1; for (int i = 0; i < 4; ++i) { int fx = x + dir[i][0]; int fy = y + dir[i][1]; if (fx>=0 && fx<n && fy>=0 && fy<n && !visited[fx][fy]) { if (map[fx][fy] == '#') ++num; else dfs(fx, fy); } }}int main(){ std::cin >> n; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) std::cin >> map[i][j]; num = 0; dfs(0, 0); if (!visited[n-1][n-1]) //没有访问过另一个角则都搜索 dfs(n-1, n-1); printf("%d\n", num * 9); return 0;}
- ural 1033. Labyrinth(dfs)
- ural 1033. Labyrinth dfs
- ural 1033. Labyrinth dfs
- URAL 1033 Labyrinth(DFS)
- URAL 1033 Labyrinth (DFS)
- URAL.1033 Labyrinth (DFS)
- ural 1033. Labyrinth
- ural 1033 Labyrinth
- Labyrinth (URAL 1033)
- URAL 1033|Labyrinth|搜索
- Ural 1033 Labyrinth(bfs)
- 【Ural 1033】 Labyrinth.(迷宫)
- POJ 2357 Labyrinth [DFS]
- The Labyrinth (dfs)
- 1033. Labyrinth
- URAL - 1145 Rope in the Labyrinth
- CF 616C The Labyrinth(dfs)
- CodeForces 616 C. The Labyrinth(dfs)
- ural 1821. Biathlon
- hdu 1241 Oil Deposits(dfs入门)
- DFS中的奇偶剪枝(转自chyshnu)
- hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)
- hdu 1312 Red and Black(dfs入门)
- ural 1033. Labyrinth(dfs)
- 图的dfs与bfs(深搜广搜)c++实现
- hdu 1209 Clock(水题)
- ural 1024. Permutations
- hdu 1518 Square(dfs)
- bjfu 1143 小蝌蚪安家(bfs入门)
- 并查集入门
- hdu 1026 Ignatius and the Princess I(bfs+priority_queue)
- ural 1910. Titan Ruins: Hidden Entrance(Titan Ruins系列题目)