UVa 657 The die is cast(DFS)
来源:互联网 发布:在淘宝网上买东西 编辑:程序博客网 时间:2024/06/06 02:21
双层DFS, X数量绝对不超过6个,所以毫无疑问,双层就可以解决掉!
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int N = 55;int n, m, numx, cnt, ans[N*N];int a[] = { 0, 0, 1, -1 };int b[] = { 1, -1, 0, 0 };char g[N][N];void dfsx ( int x, int y ) { g[x][y] = '*'; for ( int i = 0; i < 4; ++i ) { int xx = x + a[i], yy = y + b[i]; if ( g[xx][yy] == 'X' ) dfsx( xx, yy ); }}void dfs( int x, int y ) { if ( g[x][y] == 'X' ) { numx++; dfsx ( x, y ); } g[x][y] = '.'; for ( int i = 0; i < 4; ++i ) { int xx = x + a[i], yy = y + b[i]; if ( g[xx][yy] == 'X' || g[xx][yy] == '*' ) dfs( xx, yy ); }}int main(){ int icase = 1; while ( scanf("%d%d", &m, &n) != EOF && ( n || m ) ) { memset( g, '\0', sizeof(g) ); memset( ans, 0, sizeof(ans) ); cnt = 0; for ( int i = 0; i < n; ++i ) scanf("%s", g[i]); for ( int i = 0; i < n; ++i ) for ( int j = 0; j < m; ++j ) { if ( g[i][j] == 'X' || g[i][j] == '*' ) { numx = 0; dfs( i, j ); ans[cnt++] = numx; } } sort( ans, ans + cnt ); printf("Throw %d\n%d", icase++, ans[0]); for ( int i = 1; i < cnt; ++i ) printf(" %d", ans[i]); printf("\n\n"); }}
- UVa 657 The die is cast(DFS)
- uva 657 The die is cast(DFS遍历图)
- UVa 657 The die is cast(DFS*2)
- UVA - 657 The die is cast(二重dfs)
- UVA - 657 - The die is cast (两次DFS!!)
- UVA 657 The die is cast (DFS*2)
- 657 - The die is cast(dfs)
- UVA 657 The die is cast ——bfs+dfs
- UVA 657-The die is cast(dfs*2)
- UVa-657 The die is cast(dfs嵌套)
- The die is cast (DFS 双重)
- UVa 657 The die is cast
- uva 657 - The die is cast
- uva 657 - The die is cast
- uva 657 - The die is cast
- UVa 657 - The die is cast
- UVA 657 - The die is cast
- UVA 657 The die is cast
- 汇编学习笔记--CALL和RET指令
- TEXT PRINT
- 《专注——解读中国隐形冠军企业》读书笔记
- Redhat_Linux_修改主机名
- ubuntu10.10下嵌入式QT开发环境搭建手记
- UVa 657 The die is cast(DFS)
- lINUX_的hosts文件说明
- C#中Dictionary的用法及用途
- debian 设置静态IP
- linux修改_etc_hosts
- 【OpenGL】初识OpenGL4.0
- NorFlash与NandFlash区别及在mini2440上的应用
- 打卡机
- hdu 3695 Computer Virus on Planet Pandora AC自动机