Mine

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 51    Accepted Submission(s): 6

Problem Description
Have you ever played a game in Windows: Mine?
This game is played on a n*m board, just like the Pic(1)


On the board, Under some grids there are mines (represent by a red flag). There are 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 gird(i,j). Some grids are blank means there’re no mines on the 8 grids which shares a corner or a line with them.
At the beginning, all grids are back upward.
In each turn, Player should choose a back upward grid to click.
If he clicks a mine, Game over.
If he clicks a grid with a number on it , the grid turns over.
If he clicks a blank grid, the grid turns over, then check grids in its 8 directions.If the new grid is a blank gird or a grid with a number,it will be clicked too.
So If we click the grid with a red point in Pic(1), grids in the area be encompassed with green line will turn over.
Now Xiemao and Fanglaoshi invent a new mode of playing Mine. They have found out coordinates of all grids with mine in a game. They also find that in a game there is no grid will turn over twice when click 2 different connected components.(In the Pic(2), grid at (1,1) will turn over twice when player clicks (0,0) and (2,2) , test data will not contain these cases).
Then, starting from Xiemao, they click the grid in turns. They both use the best strategy. Both of them will not click any grids with mine, and the one who have 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 Xi,Yi. Please output who will win.
 
Input
Multicase
The first line of the date is an 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 Xi,Yi means the position of the ith mine.
1<=N,M<=1000 0<=K<=N*M 0<=Xi<N 0<=Yi<M
 
Output
For 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
2
3 3 0
3 3 1
1 1
 
Sample Output
Case #1: Xiemao
Case #2: Fanglaoshi
 
Source
 
Recommend
zhuyuanchen520
 

明显的SG博弈。

首先分块。连通的空白块和相连的数字块是一起的,一个单独的数字块是一类。

单独一个的数组块,SG是1.

空白块+若干个数字块,数字块个数为n的话,SG是n%2 + 1

然后bfs解决就可以了

 /* ***********************************************
Author :kuangbin
Created Time :2013/8/15 13:25:56
File Name :F:\2013ACM练习\2013多校8\1003.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ;
bool g[MAXN][MAXN];
int move[][] = {{,},{,-},{-,},{,},{,},{,-},{-,},{-,-}};
bool used[MAXN][MAXN];
int n,m;
bool check(int x,int y)
{
if(x > && g[x-][y])return true;
if(x < n- && g[x+][y])return true;
if(y > && g[x][y-])return true;
if(y < m- && g[x][y+])return true;
if(x > && y > && g[x-][y-])return true;
if(x > && y < m- && g[x-][y+])return true;
if(x < n- && y > && g[x+][y-])return true;
if(x < n- && y < m- && g[x+][y+])return true;
return false;
}
int dfs(int x,int y)
{
queue<pair<int,int> >q;
q.push(make_pair(x,y));
int cnt = ;
used[x][y] = true;
while(!q.empty())
{
pair<int,int> tmp = q.front();
q.pop();
int nx = tmp.first;
int ny = tmp.second;
if(check(nx,ny))
{
cnt++;
continue;
}
for(int i = ;i < ;i++)
{
int tx = nx + move[i][];
int ty = ny + move[i][];
if(tx < || tx >= n || ty < || ty >= m)continue;
if(used[tx][ty])continue;
if(g[tx][ty])continue;
q.push(make_pair(tx,ty));
used[tx][ty] = true;
}
}
return cnt;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase ++;
int k;
scanf("%d%d%d",&n,&m,&k);
memset(g,false,sizeof(g));
int x,y;
while(k--)
{
scanf("%d%d",&x,&y);
g[x][y] = true;
}
memset(used,false,sizeof(used));
int ans = ;
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
if(!g[i][j] && !used[i][j] && !check(i,j))
{
int tmp = dfs(i,j);
ans ^= (tmp%+);
}
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
if(!g[i][j] && !used[i][j] && check(i,j))
ans ^= ;
if(ans == )printf("Case #%d: Fanglaoshi\n",iCase);
else printf("Case #%d: Xiemao\n",iCase);
} return ;
}

HDU 4678 Mine (2013多校8 1003题 博弈)的更多相关文章

  1. HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)

    Count The Pairs Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  2. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  3. HDU 4704 Sum (2013多校10,1009题)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  4. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  5. HDU 4696 Answers (2013多校10,1001题 )

    Answers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  6. HDU 4691 Front compression (2013多校9 1006题 后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

  7. HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  8. HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)

    Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  9. HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)

    Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

随机推荐

  1. Deep Learning基础--机器翻译BLEU与Perplexity详解

    前言 近年来,在自然语言研究领域中,评测问题越来越受到广泛的重视,可以说,评测是整个自然语言领域最核心和关键的部分.而机器翻译评价对于机器翻译的研究和发展具有重要意义:机器翻译系统的开发者可以通过评测 ...

  2. shell之read命令

    一.概述 read命令接收标准输入(键盘)的输入,或者其他文件描述符的输入.得到输入后,read命令将数据放入一个标准变量中. 二.使用举例(这里仅列出一些常用的选项) 1.基本读取 #!/bin/b ...

  3. Linux下软件的安装与管理

    1.源码安装方式 2.RPM包方式安装 3.yum安装方式 4.二进制软件安装方式 1.源码安装方式 (1)下载.解压Apache源码: mkdir /apache #在根目录下创建一个apache目 ...

  4. 纯js的N级联动列表框 —— 基于jQuery

    多个列表框联动,不算是啥大问题,但是却挺麻烦,那么怎么才能够尽量方便一点呢?网上搜了一下,没发现太好用的,于是就自己写了一个.基于jQuery,无限级联动,支持下拉列表框和列表框. 先说一下步骤和使用 ...

  5. php、mysql编译配置

    与apache一起使用: Configure Command =>  './configure'  '--prefix=/home/sujunjie/local/php' '--with-apx ...

  6. poj1562 Oil Deposits(DFS)

    题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...

  7. vs.net 效率提升-自定义快捷键

    工欲善其事必先利其器,记录一下自己开发时常用的几个自定义的快捷键.做了这么多年了用着还是比较顺手的分享下~~~~设置时有时设置不成功,非得一项一项设置才可以~~~ 设置自定义快捷键位置:vs.net- ...

  8. React Native 系列(三)

    前言 本系列是基于React Native版本号0.44.3写的,相信大家看了本系列前面两篇文章之后,对于React Native的代码应该能看懂一点点了吧.本篇文章将带着大家来认识一下React N ...

  9. Hibernate 多对一注解

    在前面学习了基于配置文件的多对一关系,而在实际的开发过程中我们更多的是使用注解去开发.在这里来简单学习一下基于注解的多对一关系. 1. 创建所需要的实体 注:这里需要特别注意的是,如果使用的是mysq ...

  10. 【BZOJ 1923】1923: [Sdoi2010]外星千足虫 (高斯消元异或 | BITSET用法)

    1923: [Sdoi2010]外星千足虫 Description Input 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结果.每行 包含一个 ...