HDU 4678 Mine

Source: Internet
Author: User

Problem Descriptionhave ever played a game in Windows:mine?
This game was played on a n*m board, just like the Pic (1)


On the board, under some grids there is mines (represent by a red flag). There is numbers ' a (i,j) ' On some grids means there ' re A (I,J) mines on the 8 grids which shares A corner or A line with G IRD (I,J). Some grids is blank means there ' re no mines on the 8 grids which shares a corner or a line with them.
At the beginning, all grids is back upward.
In each turn, the Player should choose a back upward the grid to click.
If He clicks a mine, Game over.
If He clicks a grid with a number on it, the grid is turns over.
If He clicks a blank grid, the grid turns over and then check for grids in its 8 directions. If The new grid is a blank gird or a grid with a number,it would be clicked too.
So If we click the grid with a red point in Pic (1), grids in the area is encompassed with Green Line would turn over.
Now Xiemao and Fanglaoshi invent a new mode of playing Mine. They has found out coordinates of any grids with mine in a game. They also find, a game there is no grid would turn over twice when click 2 different connected components.(In the Pic (2), grid at () would turn over twice when player clicks (0,0) and (2,2), test data would not contain these C ases).
Then, starting from Xiemao, they click the grid in turns. They both use the best strategy. Both of them won't click any grids with mine, and the one who has no grid to click is the loser.
Now give you the size of board N, M, number of mines K, and positions of every mine XIYI. Please output the Who would win.
Inputmulticase
The first line of the date is a integer T, which is the number of the text cases. (T<=50)
Then T-cases follow, each case starts with 3 integers N, M, K indicates the size of the board and the number of mines. Then goes K lines, the ith line with 2 integer XIYImeans the position of the ith mine.
1<=n,m<=1000 0<=k<=n*m 0<=xI<n 0<=yI<m
Outputfor each case, first you should print ' Case #x: ', where x indicates the case number between 1 and T. Then output the winner of the game, either "Xiemao" or "Fanglaoshi". (without quotes)
Sample Input
23 3 03 3 11 1

Sample Output
Case #1: xiemaocase #2: Fanglaoshi

Source2013 multi-university Training Contest 8
Recommendzhuyuanchen520 | We have carefully selected several similar problems for you:5395 5394 5393 5390 5389


Test instructions

The game of Minesweeper, who first sweep who wins. There is a clear rule of mine clearance is that the number n around the eight must have N thunder, if it is blank, click on the blank, from the surrounding eight directions to extend, encountered the first number so far, along with the number swept away (no landmines). If it is not blank, is a separate number, then only one can be swept away. So this problem becomes the SG game. Regardless of the number alone or with the blank Unicom, the value of the SG must be positive, the initiator is sure to win. For a single number, the value of SG is obviously 1. For the Unicom block, the SG value is the number%2+1. (for example, if the individual number is a, the number of Unicom block is two, no matter how you click, the initiator will lose, because this time the value of the SG is 1^1=0. The initiator has reached the point of defeat. )。

The practice is to search for a few pieces, and then the SG game.

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include < queue> #include <set> #include <cmath>using namespace Std;int map[1002][1002];int vis[1002][1002];int N, M;int dir[8][2]= {{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};bool check (int x,int y) {if (x<n-1 &&    Amp;map[x+1][y]) return 1;    if (x>0 &&map[x-1][y]) return 1;    if (y<m-1 &&map[x][y+1]) return 1;    if (y>0 &&map[x][y-1]) return 1;    if (x<n-1 &&y>0 &&map[x+1][y-1]) return 1;    if (x>0 &&y>0&&map[x-1][y-1]) return 1;    if (x<n-1 &&y<m-1 &&map[x+1][y+1]) return 1;    if (x>0&&y<m-1 &&map[x-1][y+1]) return 1; return 0;}    int dfs (int x,int y) {queue<pair<int,int> >q;    Q.push (Make_pair (x, y));    Vis[x][y]=1;    int tot=0;        while (!q.empty ()) {pair<int,int> now=q.front ();      Q.pop ();  int Nx=now.first;        int Ny=now.second;            if (check (Nx,ny)) {tot++;        Continue            } for (int i=0; i<8; i++) {int fx=nx+dir[i][0];            int fy=ny+dir[i][1]; if (Fx>=n | | Fy>=m | | fx<0 | |            FY&LT;0) continue;            if (Vis[fx][fy]) continue;            if (Map[fx][fy]) continue;            Q.push (Make_pair (fx,fy));        Vis[fx][fy]=1; }} return tot;}    int main () {int t;    cin>>t;    int dd=0;        while (t--) {int x,y,k;        int i,j;        memset (vis,0,sizeof (VIS));        memset (map,0,sizeof (map));        cin>>n>>m;        cin>>k;            while (k--) {cin>>x>>y;        Map[x][y]=1;        } int ans=0; For (i=0, i<n; i++) for (j=0; j<m; J + +) {if (!vis[i][j] &&!check (i,j) &A mp;&!map[i][j])//Unicom block                {int Res=dfs (i,j)%2+1;                Ans^=res; }} for (i=0; i<n; i++) for (j=0; j<m; j + +) if (!vis[i][j] && check                    (I,J) &&!map[i][j])//individual numbers.        Ans^=1;        cout<< "Case #" <<++dd<< ":" << "";        if (ans==0) cout<< "Fanglaoshi" <<endl;    else cout<< "Xiemao" <<endl; }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4678 Mine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.