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. C++ 对象间通信框架 V2.0 ××××××× 之(二)

    公共头文件:ss_type_def.h ================================================================================ ...

  2. C++ Primer 第四版阅读笔记

    阅读笔记 初始化 变量定义指定了变量的类型和标识符,也可以为对象提供初始值.定义时指定了初始值的对象被称为是 已初始化的.C++ 支持两种初始化变量的形式:复制初始化和 直接初始化.复制初始化语法用等 ...

  3. 北风设计模式课程---单一职责原则(Single Responsibility Principle)

    北风设计模式课程---单一职责原则(Single Responsibility Principle) 一.总结 一句话总结: 一个类应该有且只有一个变化的原因:单一职责原则(SRP:Single Re ...

  4. 爬虫 ---- BeautifulSoup的基础使用

    #BeautifulSoup的基础使用from bs4 import BeautifulSoup #导入bs4库 html = "<p class='stylecss'>< ...

  5. malloc(50) 内存泄露 内存溢出 memory leak会最终会导致out of memory

    https://en.wikipedia.org/wiki/Memory_leak In computer science, a memory leak is a type of resource l ...

  6. LongAccumulator 源码分析

    LongAccumulator LongAccumulator 能解决什么问题?什么时候使用 LongAccumulator? 1)LongAccumulator 的逻辑和 LongAdder 基本类 ...

  7. Vue知识整理4:v-html标签

    可以在数据绑定中使用html标签,这样在变量里可以使用html标签输出结果,如下所示:

  8. 必须Mark!43个优秀的Swift开源项目推荐(转)

    作为一门集百家之长的新语言,Swift拥有着苹果先天的生态优势,而其在GitHub上各种优秀的开源项目也层出不穷.本文作者@SwiftLanguage从2014年6月苹果发布Swift语言以来,便通过 ...

  9. 04 bbed修复system文件头损坏

    04 bbed修复system文件头损坏 1 启动数据库,查看trace,在mount到open, SQL> startup mount; ORACLE instance started. To ...

  10. 没看这篇干货,别和我说你会IDEA Debug

    所谓工欲善其事必先利其器,现在idea已经成为java开发者眼中最热门最好用的IDE了.下面这篇文章将总结下idea调试的一些高级技巧. 多线程调试 直接上例子说明,比如下面这段代码 debug模式下 ...