hdu 5546 Ancient Go(dfs)
来源:互联网 发布:java 图片文字合成 编辑:程序博客网 时间:2024/06/04 19:12
题目链接
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;int t, vis[12][12], flag;char str[12][12];int dis[4][2]= {1,0,0,1,-1,0,0,-1};void dfs(int x,int y){ if(str[x][y]=='.') { flag=1; return ; } if(str[x][y]=='x') return ; for(int i=0; i<4; i++) { int xx=x+dis[i][0]; int yy=y+dis[i][1]; if(xx>=0&&xx<9&&yy>=0&&yy<9&&vis[xx][yy]==0) { vis[xx][yy]=1; dfs(xx,yy); } }}int main(){ scanf("%d",&t); int s=0; while(t--) { s++; int ff=0; for(int i=0; i<9; i++) scanf("%s",str[i]); for(int i=0; i<9; i++) { for(int j=0; j<9; j++) { if(str[i][j]=='.') { str[i][j]='x'; for(int k=0; k<4; k++) { int x1=i+dis[k][0]; int y1=j+dis[k][1]; if(x1>=0&&x1<9&&y1>=0&&y1<9&&str[x1][y1]=='o') { memset(vis,0,sizeof(vis)); vis[x1][y1]=1; flag=0; dfs(x1,y1); if(flag==0) ff=1; } } str[i][j]='.'; } } } if(ff) printf("Case #%d: Can kill in one move!!!\n",s); else printf("Case #%d: Can not kill in one move!!!\n",s); } return 0;}#include<stdio.h>#include<algorithm>#include<iostream>#include<string.h>#include<math.h>using namespace std;char mpp[12][12];int vis[12][12];int dis[4][2]= {1,0,0,1,-1,0,0,-1};int dfs(int x,int y){ int sum=0; vis[x][y]=1; for(int i=0; i<4; i++) { int xx=x+dis[i][0]; int yy=y+dis[i][1]; if(xx>=0&&xx<9&&yy>=0&&yy<9&&vis[xx][yy]==0) { if(mpp[xx][yy]=='.') { sum++; vis[xx][yy]=1; } if(mpp[xx][yy]=='o') { sum+=dfs(xx,yy);// vis[xx][yy]=1; } } } return sum;}int main(){ int t,cnt=0; scanf("%d",&t); while(t--) { int flag=0; cnt++; for(int i=0; i<9; i++) { scanf("%s",mpp[i]); } for(int i=0; i<9; i++) { for(int j=0; j<9; j++) { if(mpp[i][j]=='o') { memset(vis,0,sizeof(vis)); // vis[i][j]=1; int s=dfs(i,j); if(s==1) { flag=1; break; } } } if(flag==1) break; } if(flag) printf("Case #%d: Can kill in one move!!!\n",cnt); else printf("Case #%d: Can not kill in one move!!!\n",cnt); } return 0;}
0 0
- 【dfs】hdu 5546 Ancient Go
- HDU 5546 Ancient Go (dfs)
- hdu 5546 Ancient Go(dfs)
- hdu 5546 Ancient Go【dfs】【思维】
- HDU 5546 Ancient Go(DFS)
- HDU 5546 Ancient Go (dfs)
- HDU 5546 Ancient Go——dfs
- HDU~5546 Ancient Go(暴力dfs)
- hdu 5546 Ancient Go 枚举 DFS
- hdu 5546 Ancient Go(dfs)
- hdu 5546 Ancient Go
- HDU 5546 Ancient Go
- hdu 5546/Ancient Go
- hdu 5546 Ancient Go
- 2015 南阳 CCPC hdu 5546 Ancient Go(DFS,暴力)
- hdu 5546 Ancient Go(2016ccpc) 暴力DFS
- HDOJ 5546 Ancient Go (DFS)
- [HDOJ] 5546 Ancient Go [DFS]
- java几种常见的数据库连接
- 第十 selinux的管理
- css选择器
- 输出素数
- AC自动机模板 hdu2222
- hdu 5546 Ancient Go(dfs)
- C/C++关键字(1)
- Large Division
- Git常见错误解决方法
- vue基础一
- 高效开发使用框架请求https(xutils3 Nohttp,OkhttpUtils(zhy))
- 泛型
- JAVA 对象存放的位置
- BZOJ2194: 快速傅立叶之二