HDU

来源:互联网 发布:format java 编辑:程序博客网 时间:2024/06/07 15:21
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×88×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×99×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(1T100)T(1≤T≤100)TT 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′x′ represents a cell with black chess which owned by Yu Zhou. o′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 xx is the test case number (starting from 1) and yy 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.............o
Sample Output
Case #1: Can kill in one move!!!Case #2: Can not kill in one move!!!          
Hint
In 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.


思路:这个题目虽然有点长,但是题意还是比较好理解,大致题意就是给你一个9*9的棋盘,x代表你的棋子,o代表你对手的棋子,.代表棋盘上的空白点。问能不能按照围棋的规则下一步棋至少吃掉对手一个棋子。这个题我就是对每一个o往外进行搜索,判断是不是他和他的连同块只有一个.,如果有的话就可以一步吃掉对手的棋子,反之则不能。一开始做这个题错了三次,然后在网上看到了一组数据会使一个相同的空白点重判断(还是太烂了,自己想不出来这种错误的数据)。

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <queue>#include <map>#include <vector>#include <cmath>#include <stack>#include <algorithm>#define MAXN 20#define INF 1<<31using namespace std;char Map[MAXN][MAXN];int xx[] = {1, -1, 0, 0};int yy[] = {0, 0, 1, -1};int cnt;int vis[MAXN][MAXN];int vis1[MAXN][MAXN];void dfs(int x, int y) {    if (Map[x][y] == 'o')        vis[x][y] = 1;    for (int i = 0; i < 4; ++i) {        int gx = x + xx[i];        int gy = y + yy[i];        if (gx >= 0 && gy >= 0 && gx < 9 && gy < 9 && Map[gx][gy] == '.' && !vis1[gx][gy]) {            cnt++;            vis1[gx][gy] = 1;        }        else if (gx >= 0 && gy >= 0 && gx < 9 && gy < 9 && Map[gx][gy] == 'o' && !vis[gx][gy]) {            dfs(gx, gy);        }    }}int main() {    int T;    cin >> T;    for (int kase = 1; kase <= T; ++kase) {        memset(vis, 0, sizeof(vis));        for (int i = 0; i < 9; ++i)            cin >> Map[i];        bool flag = false;        for (int i = 0; i < 9; ++i) {            for (int j = 0; j < 9; ++j) {                if (Map[i][j] == 'o' && !vis[i][j]) {                    memset(vis1, 0, sizeof(vis1));                    cnt = 0;                    dfs(i, j);                    if (cnt == 1) {                        flag = true;                        break;                    }                }            }            if (flag)                break;        }        cout << "Case #" << kase << ": ";        if (flag)            cout << "Can kill in one move!!!\n";        else            cout << "Can not kill in one move!!!\n";    }    return 0;}


0 0
原创粉丝点击