UVA-705 Slash Maze
来源:互联网 发布:ug nx软件 编辑:程序博客网 时间:2024/06/07 04:57
UVA-705 Slash Maze
题目大意:用/ \给出一个斜着的矩阵,求里面封闭环的个数和最大长度。
解题思路:一开始就懵逼系列 , 看同学题解有的思路 , 将给的图进行放大 令 ‘\’ 变成
100
010
001
‘/’反之 然后用dfs找被1包围0的个数 除以 3即可
/************************************************************************* > File Name: UVA-705.cpp > Author: Robin > Mail: 499549060@qq.com > Created Time: 2016年08月08日 星期一 11时36分48秒 ************************************************************************/#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>using namespace std;int d[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1}};int map[3000][3000];int m,n;int num;int flag;void dfs (int x, int y) { map[x][y] = 1; for (int i = 0; i < 4; i++) if (x+d[i][0] >= 0 && x+d[i][0] < 3*n && y+d[i][1] >= 0 && y+d[i][1] < 3*m) { if (map[x+d[i][0]][y+d[i][1]] == 0) { num++; dfs (x+d[i][0], y + d[i][1]); } }else flag = 0;}int main() { int t = 1; while (scanf("%d%d\n", &m, &n) && m+n) { memset(map, 0, sizeof(map)); char c; int s = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m+1; j++) { scanf("%c", &c); if ( c == '\\') { map[3*i][3*j] = 1; map[3*i+1][3*j+1] = 1; map[3*i+2][3*j+2] = 1; } if (c == '/') { map[3*i][3*j+2] = 1; map[3*i+1][3*j+1] = 1; map[3*i+2][3*j] = 1; } } int max = 0; for (int i = 0; i < 3*n; i++) for (int j = 0; j < 3*m; j++) { flag = 1; num = 1; if (map[i][j] == 0) {dfs(i,j); if ( flag) { s++; if ( num >= max) max = num; } } } if (s == 0) printf("Maze #%d:\nThere are no cycles.\n\n",t); else printf("Maze #%d:\n%d Cycles; the longest has length %d.\n\n",t, s,max/3); t++; }}
0 0
- uva 705 - Slash Maze
- uva 705 - Slash Maze
- uva 705 - Slash Maze
- uva 705 - Slash Maze
- UVa 705 - Slash Maze
- UVA 705 - Slash Maze
- uva 705Slash Maze
- UVA 705 Slash Maze
- uva 705 Slash Maze
- Slash Maze(uva 705)
- uva 705 - Slash Maze
- UVa 705 - Slash Maze
- UVA 705 Slash Maze
- uva 705 Slash Maze
- UVA 705 Slash Maze
- UVA - 705 Slash Maze
- UVA 705 - Slash Maze
- UVA - 705 Slash Maze
- oracle11g静默安装
- UVA-657 The die is cast
- UVA-784 Maze Exploration
- POJ2559 单调队列
- java编程思想 bruce Eckel chapter2一切都是对象
- UVA-705 Slash Maze
- 添加bitcode的支持:iOS App,App Extension以及Watch App
- hdoj2059龟兔赛跑(DP)
- 【HDU 杭电 1260 Tickets】
- AngularJS之表达式
- UVA-439 Knight Moves
- java通过JDBC获取MySQL的数据实现
- VNC服务器空间不足:shell脚本检查回收站大小,提示清理
- 记录 boost 中 使用 asio 编写 server和client代码片段