您的位置:首页 > 编程语言 > Go语言

hdu5546 Ancient Go DFS搜索 国庆咸鱼

2016-10-05 17:00 337 查看

Ancient Go

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1660    Accepted Submission(s): 528Problem DescriptionYu 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:⋅Thegame is played on a 8×8 cellboard, the chess can be put on the intersection of the board lines, so there are 9×9 differentpositions to put the chess.⋅YuZhou always takes the black and Su Lu the white. They put the chess onto the game board alternately.⋅Thechess 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.⋅Whenone 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'schess. InputThe first line of the input gives the number of test cases, T(1≤T≤100). T testcases 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. ′.′ representsan empty cell. ′x′ representsa cell with black chess which owned by Yu Zhou. ′o′ representsa cell with white chess which owned by Su Lu. OutputFor each test case, output one line containing Case #x: y, where x isthe test case number (starting from 1) and y is Cankill 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.............o Sample Output
Case #1: Can kill in one move!!!Case #2: Can not kill in one move!!!HintIn the first test case, Yu Zhou has 4 different ways to kill Su Lu's component.In the second test case, there is no way to kill Su Lu's component. SourceThe 2015 China Collegiate Programming Contest看到数据量和样例就感觉是搜索。。。于是开始搜索。。。判断一个o块周围是否有超过两个 “ 。”,样例过了。。但是wa得很迷。。。然后自己造数据发现原先判断是错的。。。反例如下:..................xxx......ooox.....o.ox.....xxx.................................这个本来应该是判断可以的,但我因为重复统计了。所以给判不行。然后就改成只能对o旁边的.做一次修改成x的操作,事后还原即可,小细节wa了很多。。现在要慢慢的改掉无限提交流的习惯饿了。。。。下面代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>#include <set>#include <map>#include <vector>#include <queue>#include <cmath>using namespace std;const int maxn=20;char save[maxn][maxn];int move_x[4]={0,0,1,-1};int move_y[4]={1,-1,0,0};//xoint ans;pair<int,int> maho;void dfs(int x,int y){save[x][y]='x';int i;for(i=0;i<4;i++){int dx=x+move_x[i];int dy=y+move_y[i];if(dx>=1&&dx<=9&&dy>=1&&dy<=9){if(save[dx][dy]=='o'){dfs(dx,dy);}else if(save[dx][dy]=='.'){if(ans==0){save[dx][dy]='x';maho=make_pair(dx, dy);ans++;}else{ans++;}}}}}int main(){int t,i,j;scanf("%d",&t);int rnd=1;while(t--){for(i=1;i<=9;i++){for(j=1;j<=9;j++){cin>>save[i][j];}}bool flag=false;for(i=1;i<=9;i++){save[0][i]='x';save[10][i]='x';save[i][0]='x';save[i][10]='x';}for(i=1;i<=9;i++){for(j=1;j<=9;j++){if(save[i][j]=='o'){ans=0;dfs(i, j);if(ans>0){save[maho.first][maho.second]='.';}if(ans<=1){flag=true;//cout<<"haha!"<<endl;}}}}if(flag){printf("Case #%d: Can kill in one move!!!\n",rnd);}else{printf("Case #%d: Can not kill in one move!!!\n",rnd);}rnd++;}return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: