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. Linux运维常见问题解决集锦【转】

    作为linux运维,多多少少会碰见这样那样的问题或故障,用点心,平时多注意积累,水平肯定越来越高. 下面就是常见问题解决集锦:   1.shell脚本不执行 问题:某天研发某同事找我说帮他看看他写的s ...

  2. caffe Python API 之Inference

    #以SSD的检测测试为例 def detetion(image_dir,weight,deploy,resolution=300): caffe.set_mode_gpu() net = caffe. ...

  3. Eloqument 学习

    参考地址:https://d.laravel-china.org/docs/5.5/eloquent#mass-assignment

  4. ntp 校时程序

    //effect:send ntp packet and get the ntp packet ,make the time OK//2014.7.31 is OK//#include <sys ...

  5. java并发编程实战笔记---(第五章)基础构建模块

    . 5.1同步容器类 1.同步容器类的问题 复合操作,加容器内置锁 2.迭代器与concurrentModificationException 迭代容器用iterator, 迭代过程中,如果有其他线程 ...

  6. JavaWeb知识回顾-servlet生命周期。

    Servlet生命周期 生命周期,很容易理解,拿人来说,就是你从出生到离开的这一过程.无论是什么技术,只要谈到生命周期都可以这样理解. Servlet的生命周期就是从它被创建到毁灭的过程,整个过程可以 ...

  7. 安卓使用WebView清除缓存

    原文:https://blog.csdn.net/liwei123liwei123/article/details/52624826 Android 清除WebView缓存 最近项目中需要用WebVi ...

  8. c++ primer 5 表达式

    简单总结下容易忽视的地方和易错点吧 1 常用的位操作符,leecode很多算法题都是靠位运算解决的 2 箭头操作符 -> 等价于(*  ).   对指针的成员操作 3 sizeof操作符 对 c ...

  9. android开发笔记,杂

    Mapping文件地址: mapping文件用于在代码被混淆后,还原BUG信息. release模式编译项目即可产生,相对位置:工程\build\outputs\mapping\release 需要c ...

  10. html禁止浏览器默认行为,让页面更像应用。

    在html或body行内写入:oncontextmenu="return false" ondragstart='return false;' onselectstart=&quo ...