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. mac pro上安装docker

    1.进入一下地址进行下载docker https://download.docker.com/mac/stable/Docker.dmg 进入后进行下载后进行安装 2.将其拖动到Appliaction ...

  2. python中list的底层实现

    这里不讨论具体的实现细节,主要是转载这篇文章: 顺序表的原理与python中的list类型. 原文就不贴过来了,总结一下: 确定数据类型的意义在于确定一个数据在内存中占据的空间大小以及如何解释一段内存 ...

  3. CSU 1355 地雷清除计划

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1355 好题,根本想不到是网络流. 模型如图: 假想从右上角到左下角有一条阻拦线,我们就是 ...

  4. nginx配置tomcat集群

    显示nginx的核心配置 #user nobody;worker_processes 1; events { worker_connections 1024;    #并发连接数} http { in ...

  5. [实战]MVC5+EF6+MySql企业网盘实战(19)——BJUI和ztree

    写在前面 上周在博客园看到一篇通用权限系统的文章,看到他那个UI不错,这里就研究了一下,将网盘的UI修改为他的那个,感兴趣的可以参考:http://b-jui.com/ 系列文章 [EF]vs15+e ...

  6. elementUI 学习入门之 radio 单选框

    Radio 单选框 基础用法 选项默认可见,选项不宜过多,选项过多建议使用 select 选择器 使用 Radio 组件,需要设置 v-model 绑定变量,选中意味着变量的值为相应 Radio  l ...

  7. STL容器 -- Bitset

    核心内容:Bitset 是 STL 中的二进制容器, 存放的时 bit 位元素, 每一位只占一个 bit 位, 取值 0 或者 1, 可以像整形元素一样按位与或非, 并且大大优化了时间和空间复杂度. ...

  8. Java Web开发——HTML CSS JavaScript 杂记

    HTML是一种在互联网上常见的网页制作标注性语言,并不能算作一种程序设计语言.因为它相对程序设计语言来说缺少了其应所有的特征.对于网站设计人员来说,只使用HTML是不够的,需要在页面中引入CSS样式. ...

  9. Bzoj2002/洛谷P3203 [HNOI2010]弹飞绵羊(分块)

    题面 Bzoj 洛谷 题解 大力分块,分块大小\(\sqrt n\),对于每一个元素记一下跳多少次能跳到下一个块,以及跳到下一个块的哪个位置,修改的时候时候只需要更新元素所在的那一块即可,然后询问也是 ...

  10. AppDomain.CurrentDomain.BaseDirectory是什么

    AppDomain.CurrentDomain.BaseDirectory 是获取基目录,它由程序集冲突解决程序用来探测程序集.由显示的路径可以看出,它代表的是程序集所在的目录,它具有读取和写入的属性 ...