Mine

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

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;空白的为0; 然后开始扫一遍,当遇到空白的就dfs空白的一块并把它标记掉(可以标记为2)。如此就把含空白的快分离出来了! 最后只要数一下含1的个数即可; #pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int n,m,lei,ans,num;
int maz[][]; void dfs(int x,int y)
{
if(x<||x>n||y<||y>m) return ;
if(maz[x][y]==)
{
maz[x][y]=;
dfs(x,y-);
dfs(x,y+);
dfs(x-,y-);
dfs(x-,y);
dfs(x-,y+);
dfs(x+,y-);
dfs(x+,y);
dfs(x+,y+);
}
else if(maz[x][y]==)
{
num++;
maz[x][y]=;
}
} int main()
{
int t,cas,i,j,tx,ty,res;
scanf("%d",&t);
cas=;
while(t--)
{
memset(maz,,sizeof(maz));
scanf("%d%d%d",&n,&m,&lei);
for(i=;i<=lei;i++)
{
scanf("%d%d",&tx,&ty);
tx++;
ty++;
maz[tx][ty]=;
if(maz[tx][ty-]==) maz[tx][ty-]=;
if(maz[tx][ty+]==) maz[tx][ty+]=;
if(maz[tx+][ty-]==) maz[tx+][ty-]=;
if(maz[tx+][ty]==) maz[tx+][ty]=;
if(maz[tx+][ty+]==) maz[tx+][ty+]=;
if(maz[tx-][ty-]==) maz[tx-][ty-]=;
if(maz[tx-][ty]==) maz[tx-][ty]=;
if(maz[tx-][ty+]==) maz[tx-][ty+]=;
}
ans=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(!maz[i][j])//遇见空格,就开始dfs这一块!!
{
num=;//num为这一块总共有几个格子(attention!连在一起的所有的空白格子算一大格!)
dfs(i,j);
if(num%==) ans^=;
else ans^=;
}
}
}
res=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(maz[i][j]==) res++;
}
}
if(res%==) ans^=;
if(ans==) printf("Case #%d: Fanglaoshi\n",cas++);
else printf("Case #%d: Xiemao\n",cas++);
}
return ;
}

HDU 4678 Mine(博弈)的更多相关文章

  1. hdu 4678 Mine

    HDU 4678 把点开空地时会打开的一大片区域看成一块,题目中说到,在一盘游戏 中,一个格子不可能被翻开两次,说明任意两块空地不会包含相同的格子. 那么就可以看成一个组合游戏. 当空地旁边没连任何数 ...

  2. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  3. HDU 4678 Mine SG博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=4678 自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG 这里子游戏之间没有影响 ...

  4. hdu 4678 Mine 博弈论

    这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...

  5. HDU 4315 阶梯博弈变形

    n个棋子,其中第k个是红色的,每个棋子只能往上爬,而且不能越过.重叠其他棋子,谁将红色棋子移到顶部谁赢. 由于只能往上爬,所以很像阶梯博弈.这题有2个限制,棋子不能重叠,有红棋存在 首先不考虑红色棋, ...

  6. HDU 1564 简单博弈 水

    n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...

  7. 2020杭电多校 10C / HDU 6879 - Mine Sweeper (构造)

    HDU 6879 - Mine Sweeper 题意 定义<扫雷>游戏的地图中每个空白格子的值为其周围八个格子内地雷的数量(即游戏内临近地雷数量的提示) 则一张地图的值\(S\)为所有空白 ...

  8. HDU-4678 Mine 博弈SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...

  9. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

随机推荐

  1. 普通用户sudo权限

    需求: 1>创建一个saipu普通用户,不允许使用 rm 和 passwd root 和 sudo su - root 命令,其他命令均允许且 sudo 时不用输入密码 2>创建一个lwd ...

  2. 纯css实现手机通讯录

    我们经常在手机上看到通讯录列表,这类布局一般有两个显著的效果 首字母吸顶 快速定位 下面我们来实现一下 页面结构 这里页面结构很简单,就是两个列表 <div class="con&qu ...

  3. Django中间件添加白名单

     一定记得配置 补充一点中间件是工作流程 中间件的详细流程 补充一点需求:在不用中间件的情况和下用装饰器做登陆的阻挡 在django中有自带的 登陆闭包函数只需要引出来就可以直接用了下面是步骤 在se ...

  4. 阶段1 语言基础+高级_1-3-Java语言高级_03-常用API第二部分_第5节 StringBuilder类_1_StringBuilder的原理

    字符串不可变.字符串的缓冲区是可以变的 字符串Sting的底层,被final修饰的不可变的数组 a+b+c最终会产生5个字符串

  5. Week 7 - 714. Best Time to Buy and Sell Stock with Transaction Fee & 718. Maximum Length of Repeated Subarray

    714. Best Time to Buy and Sell Stock with Transaction Fee - Medium Your are given an array of intege ...

  6. python实现建立websocket通信

    实现代码如下: #websocket协议通信 import threading import time import websocket def when_message(ws, message): ...

  7. [Python3 填坑] 016 对 __getattr__ 和 __setattr__ 举例

    目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 __getattr__ 2.2 __setattr__ 1. print( 坑的信息 ) 挖坑时间:2019/04/07 明细 坑的编码 ...

  8. 将java项目转换成javaWeb项目

    1.Ctrl+Shift+R快捷键:找到此项目中的.project文件,打开修改文件内容 在<natures> </natures>代码标签中,添加些内容: <natur ...

  9. Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ItemsCustom' in 'class com.pojo.OrderDetailCustom

    再用 junit 测试MyBatis时发现的错误: org.apache.ibatis.exceptions.PersistenceException: ### Error querying data ...

  10. Spring Boot & ES 实战,值得参考!

    作者:废物大师兄 cnblogs.com/cjsblog/p/9756978.html 1. 前言 1.1. 集成方式 Spring Boot中集成Elasticsearch有4种方式: REST C ...