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. 解决word2016鼠标每点击一下就出现一个保存的圆圈

    问题描述:今天打开word2016时,点击鼠标,随着鼠标会出现一个圆圈,让人看着很不习惯,通过查阅资料和亲自实践,记录在博客中. 由于自己之前装了PowerDesigner,PowerDesigner ...

  2. Linux环境Nginx安装、调试以及PHP安装

    linux版本:64位CentOS 6.4 Nginx版本:nginx1.8.0 php版本:php5.5 1.编译安装Nginx 官网:http://wiki.nginx.org/Install 下 ...

  3. oracle 一个网站

    http://www.oracle.com/technetwork/cn/articles/11g-pivot-101924-zhs.html

  4. HDU 1285 确定比赛名次(拓扑排序模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 题目大意:有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行 ...

  5. Jmeter-----保存到响应文件

    在jmeter中使用保存响应到文件 ------适用于非GUI模式执行脚本时,无法查看报错的信息. 1.添加组件: 2.各个配置项说明: 1.名称:即组件在整个测试计划中的名称显示,建议设置为用意义的 ...

  6. 学习build-web-application-with-golang第四章内容

    GITHUB网址: https://github.com/astaxie/build-web-application-with-golang 内容 4.表单 4.1 处理表单的输入 4.2 验证表单的 ...

  7. zabbix 监控 oracle 数据库

    https://blog.csdn.net/dyllove98/article/details/41120853

  8. [实战]MVC5+EF6+MySql企业网盘实战(26)——音乐列表

    写在前面 本篇文章将实现,音乐列表,同样和其他列表的不同之处,在于查询条件的不同. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网 ...

  9. loadrunner测试ajax框架

    loadrunner测试ajax框架的系统时,录制回放都没有报错,但是回放后系统中没有产生数据,解决方法 loadrunnerajax框架测试脚本headerajax [问题描述]用loadrunne ...

  10. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表

    E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...