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. Spring Cloud架构教程 (四)服务网关(路由配置)

    传统路由配置 所谓的传统路由配置方式就是在不依赖于服务发现机制的情况下,通过在配置文件中具体指定每个路由表达式与服务实例的映射关系来实现API网关对外部请求的路由. 没有Eureka和Consul的服 ...

  2. Fabric基础架构原理(一)

    Linux基金会于2015年12月启动了名为“超级账本”(Hyperledger)的开源项目,旨在推动各方协作,共同打造基于区块链的企业级分布式账本底层技术,用于构建支撑业务的行业应用和平台. 超级账 ...

  3. 常见的七种Hadoop和Spark项目案例

    常见的七种Hadoop和Spark项目案例 有一句古老的格言是这样说的,如果你向某人提供你的全部支持和金融支持去做一些不同的和创新的事情,他们最终却会做别人正在做的事情.如比较火爆的Hadoop.Sp ...

  4. Ueditor1.4.4 Jsp版本视频上传成功,重新编辑时无法打开、在文本框内无法显示、html源码显示src为空

    1. 编辑 ueditor.config.js 第355行 将 whitList 改为 whiteList 2.编辑ueditor.all.js 注释掉7343.7344.7345行代码,即: var ...

  5. sudo无需输入密码设置

    注意这个是无需输入密码的设置,不是无需输入sudo 1 在终端输入: sudo gedit /etc/sudoers 2 在打开文件中的root   ALL=(ALL:ALL) ALL下一行添加&qu ...

  6. Js dom 学习

    节点类型 文档节点: 一棵DOM树的顶端是文档节点,它呈现为整个页面(相当于document对象),当需要访问任何元素.属性或文本节点时,都需要通过文档节点来进行导航.(document.) 元素节点 ...

  7. axios 拦截以及 API简单配置(element)

    在某些情况下,有时候会在接口请求的API中需要拿到存在浏览器中的COOKIE,调用的方式可以为: // 获取浏览器Cookie function getCookie(cname) { var name ...

  8. c++静态成员变量初始化时不受访问权限控制

    1.要在类外初始化,const 成员变量才能在类内初始化 2.初始化在类外,而不在main函数内 class A{ private: string name; A(){ name = "a& ...

  9. layui基本使用(动态获取数据,并把需要的数据传到新打开的窗口)

    <div class="xiaoxi">\n' + ' <div class="layui-row">\n' + ' <input ...

  10. mybatis初步理解

    mybatis概念   mybatis 是一款轻量级的orm的数据持久框架,封装jdbc 对开发提供了便利,但是性能会比jdbc低,从开发的角度来说,现在是比较流行的 掌握上比较容易,也支持缓存,级联 ...