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博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
随机推荐
- 【翻译】详解HTML5 自定义 Data 属性
原标题:HTML5 Custom Data Attributes (data-*) 你是否曾经使用 class 或 rel 来保存任意的元数据,只为了使你的JavaScript更简单?如果你回答是的, ...
- .NET(c#) 移动APP开发平台 - Smobiler(2) - 平台介绍
看到大家很多人在后台问我一些问题,所以准备写一个系列了,下面给个目录 目录: .NET(c#) 移动APP开发平台 - Smobiler(1) 环境的搭建及上手第一个应用 类似开发WinForm的方式 ...
- 3D Computer Grapihcs Using OpenGL - 03 OpenGL Buffer Data
本节绘制一个三角形,并讲解Buffer Object-缓冲对象 OpenGL的窗口坐标 屏幕中心为坐标原点,横向朝右为x正方向,纵向朝上为y正方向,最大值最小值分别为1,-1. Buffer Obje ...
- token与安全
http://ju.outofmemory.cn/entry/134189 关于 Token,你应该知道的十件事 https://blog.csdn.net/Fabulous1111/art ...
- Oracle诊断: 服务器启后,无法连接
Oracle 服务器启后,使用Toad 客户端连接oracle 时候,遇到下面的错误: oracle ORA-12514: TNS: no listener TNS: listener does no ...
- 转:KVM使用NAT联网并为VM配置iptables端口转发,kvmiptables
转载地址:https://www.ilanni.com/?p=7016 在前面的文章中,我们介绍KVM的虚拟机(以下简称VM)都是通过桥接方式进行联网的. 本篇文章我们来介绍KVM的VM通过NAT方式 ...
- optistruct线性求解一次二次单元应力位移比较
通过分析比较10mm.5mm.3mm.1mm的网格模型, 网格越细密: 位移与应力均趋于恒定值(收敛): 一次与二次单元的应力区域一致: 一次与二次单元的位移相差11.3%,一次单元的位移小. 所用的 ...
- Retrofit RestAdapter 配置说明
RestAdapter.Builder builder = new RestAdapter.Builder(); builder.setEndpoint(ip地址 ...
- EF2:Entity Mysql Sample
1)概念 Entity Framework: 全称ADO.NET Entity Framework,是微软开发的基于ADO.NET的ORM(Object/Relational Mapping)框架.百 ...
- 003-js-MD5
源码 /* global define */ ;(function ($) { 'use strict' /* * Add integers, wrapping at 2^32. This uses ...