HDU 4678 Mine(博弈)
Mine
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 658 Accepted Submission(s): 186
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.3 3 0
3 3 1
1 1
Case #2: Fanglaoshi
博弈题;用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(博弈)的更多相关文章
- hdu 4678 Mine
HDU 4678 把点开空地时会打开的一大片区域看成一块,题目中说到,在一盘游戏 中,一个格子不可能被翻开两次,说明任意两块空地不会包含相同的格子. 那么就可以看成一个组合游戏. 当空地旁边没连任何数 ...
- HDU 4678 Mine (2013多校8 1003题 博弈)
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- HDU 4678 Mine SG博弈
http://acm.hdu.edu.cn/showproblem.php?pid=4678 自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG 这里子游戏之间没有影响 ...
- hdu 4678 Mine 博弈论
这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...
- HDU 4315 阶梯博弈变形
n个棋子,其中第k个是红色的,每个棋子只能往上爬,而且不能越过.重叠其他棋子,谁将红色棋子移到顶部谁赢. 由于只能往上爬,所以很像阶梯博弈.这题有2个限制,棋子不能重叠,有红棋存在 首先不考虑红色棋, ...
- HDU 1564 简单博弈 水
n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...
- 2020杭电多校 10C / HDU 6879 - Mine Sweeper (构造)
HDU 6879 - Mine Sweeper 题意 定义<扫雷>游戏的地图中每个空白格子的值为其周围八个格子内地雷的数量(即游戏内临近地雷数量的提示) 则一张地图的值\(S\)为所有空白 ...
- HDU-4678 Mine 博弈SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
随机推荐
- Android Bluetooth 文件接收路径修改方法
修改文件: packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java 相关代码片段: ...
- hihocoder1286 : 子矩阵求和
http://hihocoder.com/problemset/problem/1286 题解 NB分析题. 首先我们令\(s[i][j]\)表示以\((i,j)\)为左上角的矩形的权值和. 因为\( ...
- Spring Cloud教程(八)云原生应用程序
Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线).分布式系统的协调导致了样板模式, 使用Spring Clo ...
- 在命令行运行java代码
因为尝试将运行结果通过管道命令保存,所以尝试在命令行(不借助lde来运行java代码,结果折腾了半天) 仿照的是eclipse创建文件目录的方式 最终解决方法是: #/bin/bash root_di ...
- android中各种组件的生命周期问题
1,activiy生命周期 http://www.ibm.com/developerworks/cn/opensource/os-cn-android-actvt/ 结合ativity的状态转换来看才 ...
- Laravel 在homestead 平台上命令
使用以下命令查看 Heroku 站点地址: $ heroku domains
- 测开之路八十七:HTML之a标签的用法
初始化的HTML结构为,只需要在body里面加网页的标签和要显示的内容即可 <!DOCTYPE html><html lang="en"><head& ...
- k8s创建资源
一.创建方式分类: 命令 vs 配置文件 Kubernetes 支持两种方式创建资源: 1.用 kubectl 命令直接创建(适用于少数的pod创建) kubectl run httpd- ...
- Java 与 C++ 的比较
参考 Java 中,一切皆是类 Java 中,所有数据或方法都要放在类中.如果想获得与全局函数等价的功能,可将static方法和static数据放在类里.而 C++ 中有 struct 结构.enum ...
- js模块化编程之CommonJS和AMD/CMD!
有了模块,我们就可以更方便地使用别人的代码,想要什么功能,就加载什么模块. 但是,这样做有一个前提,那就是大家必须以同样的方式编写模块,否则你有你的写法,我有我的写法,岂不是乱了套! 于是下面三个模块 ...