UVA 657 The die is cast (DFS*2)
来源:互联网 发布:java简单打飞船游戏 编辑:程序博客网 时间:2024/05/16 15:22
分析:双DFS,一个搜索*,一个搜索X;(遍历完每个地方后把他变为背景‘.’)
题意就是判断X(连通算一个,四方向遍历)的个数,也就是筛子的点数。
题意很简单,但程序写起来还是有难度的,WA数次。(本题类似于古代象形符号)
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <vector>#include <cstdlib>using namespace std;const int maxn=55;char pic[maxn][maxn];int cnt;int i_cmp(void const *x,void const *y){ return *(int*)x-*(int*)y;}void dfs(int r,int c){ if (pic[r][c]!='X')return ; else pic[r][c]='.'; dfs(r-1,c);dfs(r,c-1); dfs(r,c+1);dfs(r+1,c);}void dfs2(int r,int c){ if (pic[r][c]=='.') return ; if (pic[r][c]=='X') { dfs(r,c); cnt++; } pic[r][c]='.'; dfs2(r-1,c);dfs2(r,c-1); dfs2(r,c+1);dfs2(r+1,c);}int main(){ int kase=0,dote[100]; int n,m,ct; while (scanf("%d%d",&n,&m)==2&&m&&n) { memset(pic,'.',sizeof(pic)); for(int i=1; i<=m; i++) { getchar(); for(int j=1; j<=n; j++) scanf("%c",&pic[i][j]); } ct=0; for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) { if (pic[i][j]=='*') { cnt=0; dfs2(i,j); dote[ct++]=cnt; } } printf("Throw %d\n", ++kase); qsort(dote,ct,sizeof(dote[0]),i_cmp); for(int i=0; i<ct; i++) { if(i) printf(" "); printf("%d",dote[i]); } printf("\n\n"); } return 0;}
0 0
- UVa 657 The die is cast(DFS*2)
- UVA 657 The die is cast (DFS*2)
- 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)
- UVA - 657 - The die is cast (两次DFS!!)
- 657 - The die is cast(dfs)
- UVA 657 The die is cast ——bfs+dfs
- 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
- UVA-152 Tree's a Crowd
- UVA 299 Train Swapping
- pyqt桌面开发--HelloWorld
- UVA 755 487--3279
- Rails(UVa514)(栈)
- UVA 657 The die is cast (DFS*2)
- AWS 80 亿美元的营收, 代表著这个世界将更扁平; 过往的产品开发思维, 工程实践已不适用了
- Ubuntu14.04系统下载Google Android源码方法
- 2016太原网络营销师郭文军【运城】讲解事件营销掌握的重点?
- ES6学习——新的语法:const
- Java中的锁——ReentrantReadWriteLock(读写锁)
- Unity3d shader之SWAP Force Depth-of-Field Shader
- Roman to Integer
- Android 性能分析工具dumpsys的使用(自己增加一部分在后面)