UVA657- The Settlers of Catan
来源:互联网 发布:淘宝卖家引流技巧 编辑:程序博客网 时间:2024/05/02 01:28
题意:给出图像,输出所表示点数的升序
思路:利用两次DFS,一次用来搜索色子的位置,在这个DFS中再嵌套一个DFS,搜索点数的大小。。。。用标记的方法,WA了无数次,而且还找不到原因。。。。所以就将遍历过的点都转化为‘.’,才A了。。。万般无奈。。。
#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>#include<algorithm>using namespace std;char a[55][55];int result[100];int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};int cnt;void dfs1(int x,int y) {if (a[x][y]!='X')return ;elsea[x][y]='.';dfs1(x-1,y); dfs1(x,y-1);dfs1(x,y+1);dfs1(x+1,y);}void dfs(int x,int y) {if (a[x][y]=='.')return ;if (a[x][y]=='X') {dfs1(x,y);cnt++;}a[x][y]='.';dfs(x-1,y);dfs(x,y-1);dfs(x,y+1);dfs(x+1,y);}int main() {int w, h, num=1, ct;while (scanf("%d%d", &w, &h) != EOF) {if (w == 0 && h == 0) break;memset(a,'.',sizeof(a));for(int i = 1; i <= h; i++) {getchar();for(int j = 1; j <= w; j++)scanf("%c", &a[i][j]);}ct = 0;for(int i = 1; i <= h; i++)for(int j = 1; j <= w; j++)if (a[i][j] == '*' || a[i][j] == 'X') {cnt = 0;dfs(i,j);result[ct++] = cnt;}printf("Throw %d\n",num++);sort(result, result + ct);for(int i = 0; i < ct; i++) {if(i)printf(" ");printf("%d", result[i]);}printf("\n\n");}return 0;}
- UVA657- The Settlers of Catan
- The Settlers of Catan
- 539--The Settlers of Catan
- 539The Settlers of Catan
- 539 - The Settlers of Catan
- uva539 - The Settlers of Catan
- UVaOJ539 - The Settlers of Catan
- UVA539- The Settlers of Catan
- 539 - The Settlers of Catan
- UVA The Settlers of Catan
- The Settlers of Catan POJ
- zju1947 The Settlers of Catan (DFS)
- UVa 539 The Settlers of Catan
- Uva 539 The Settlers of Catan
- uva 539 - The Settlers of Catan
- uva 539 - The Settlers of Catan
- uva 539 - The Settlers of Catan
- UVa 539 - The Settlers of Catan
- python property 函数用法
- 基于遗传算法的高校排课系统研究
- ArcGIS 10.2 操作SQLite
- hdu1690 Bus System (dijkstra)
- UVA539- The Settlers of Catan
- UVA657- The Settlers of Catan
- 使用winrar打包文件
- Shell简易学习练习
- 背包问题九讲(转)
- 校招季——操作系统的存储管理
- Java与C#平台通信 WCF CXF SOAP
- 网络验证
- 数学之路(3)-机器学习(3)-机器学习算法-神经网络[18]
- 采用蒙特卡洛方法计算PI的值