2015南阳CCPC G - Ancient Go dfs
2015-10-30 19:57
507 查看
[b]G - Ancient Go[/b]
Yu Zhou always takes the black and Su Lu the white. They put the chess onto the game board alternately.
The chess of the same color makes connected components(connected by the board lines), for each of the components, if it's not connected with any of the empty cells, this component dies and will be removed from the game board.
When one of the player makes his move, check the opponent's components first. After removing the dead opponent's components, check with the player's components and remove the dead components.One day, Yu Zhou was playing ancient go with Su Lu at home. It's Yu Zhou's move now. But they had to go for an emergency military action. Little Qiao looked at the game board and would like to know whether Yu Zhou has a move to kill at least one of Su Lu's chess.
Description
Yu Zhou likes to play Go with Su Lu. From the historical research, we found that there are much difference on the rules between ancient go and modern go.Here is the rules for ancient go they were playing:The game is played on a 8×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×9 different positions to put the chess.Yu Zhou always takes the black and Su Lu the white. They put the chess onto the game board alternately.
The chess of the same color makes connected components(connected by the board lines), for each of the components, if it's not connected with any of the empty cells, this component dies and will be removed from the game board.
When one of the player makes his move, check the opponent's components first. After removing the dead opponent's components, check with the player's components and remove the dead components.One day, Yu Zhou was playing ancient go with Su Lu at home. It's Yu Zhou's move now. But they had to go for an emergency military action. Little Qiao looked at the game board and would like to know whether Yu Zhou has a move to kill at least one of Su Lu's chess.
Input
The first line of the input gives the number of test cases, T(1≤T≤100). T test cases follow. Test cases are separated by an empty line. Each test case consist of 9 lines represent the game board. Each line consists of 9 characters. Each character represents a cell on the game board. . represents an empty cell. x represents a cell with black chess which owned by Yu Zhou. o represents a cell with white chess which owned by Su Lu.Output
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is Can kill in one move!!! if Yu Zhou has a move to kill at least one of Su Lu's components. Can not kill in one move!!! otherwise.Sample Input
2 .......xo ......... ......... ..x...... .xox....x .o.o...xo ..o...... .....xxxo ....xooo. ......ox. .......o. ...o..... ..o.o.... ...o..... ......... .......o. ...x..... ........oSample Output
Case #1: Can kill in one move!!! Case #2: Can not kill in one move!!! 题意:下围棋规则,给你一个9*9的棋盘:上面有圈叉,现在轮到你下叉子,判断是否能够杀死至少一枚圈 题解;直接枚举所有下子的情况,判断是否叉围住了至少一个圈。……——……
///1085422276 #include<bits/stdc++.h> using namespace std ; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,127,sizeof(a)) #define FOR(i,a,b) for( int i=a;i<=b;i++) #define inf 100000 inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } //**************************************** #define maxn 11 int ss[4][2]={-1,0,0,-1,1,0,0,1}; bool flag,vis[maxn][maxn]; char mp[maxn][maxn]; bool check(int x,int y){ if(x<0||y<0||x>=9||y>=9)return 1; return 0; } void dfs(int x,int y){ if(flag)return ; for(int i=0;i<4;i++){ int xx=x+ss[i][0]; int yy=y+ss[i][1]; if(check(xx,yy)||vis[xx][yy])continue; if(mp[xx][yy]=='.'){ flag=1;return ; } if(mp[xx][yy]=='o'){ vis[xx][yy]=1; dfs(xx,yy); if(flag)return ; } } } int main(){ int T=read(); int oo=1; while(T--){ for(int i=0;i<9;i++){ scanf("%s",mp[i]); } bool GG=0; for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ if(mp[i][j]=='.'){ mp[i][j]='x'; for(int k=0;k<4;k++){ mem(vis); int xx=i+ss[k][0]; int yy=j+ss[k][1]; if(check(xx,yy))continue; if(mp[xx][yy]=='o') { flag=0; vis[xx][yy]=1; dfs(xx,yy); if(!flag){ GG=1;//cout<<i<<" "<<j<<endl; } if(GG){break;} } } mp[i][j]='.'; } if(GG){break;} } if(GG){break;} } printf("Case #%d: ",oo++); if(GG){ cout<<"Can kill in one move!!!"<<endl; } else { cout<<"Can not kill in one move!!!"<<endl; } } return 0; }View Code
相关文章推荐
- UVALive 6886 Golf Bot
- Google图片搜索的原理
- Algorithms—208.Implement Trie (Prefix Tree)
- 浅析Go语言编程当中映射和方法的基本使用
- MIT算法导论——第一讲.Analysis of algorithm
- goolge官方推荐图片加载框架glide使用介绍
- Django 中的用户认证
- Django运行方式及处理流程总结
- django 简单的邮件系统
- django 注册、登录及第三方接口程序(3):验证之正则表达式
- django 注册、登录及第三方接口程序(2):扩展User表
- django 注册、登录及第三方接口程序(1):基础知识
- Go语言中函数的参数传递与调用的基本方法
- django 一些相关问题
- Go语言流程控制之goto语句与无限循环
- Django 源码小剖: 应用程序入口 WSGIHandler
- Django 源码小剖: Django 中的 WSGI
- Emacs中多个golang项目的配置方法
- Django 源码小剖: 初探 WSGI
- django 登陆认证