HDU 4678 Mine (2013多校8 1003题 博弈)
Mine
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 51 Accepted Submission(s): 6
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.
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
3 3 0
3 3 1
1 1
Case #2: Fanglaoshi
明显的SG博弈。
首先分块。连通的空白块和相连的数字块是一起的,一个单独的数字块是一类。
单独一个的数组块,SG是1.
空白块+若干个数字块,数字块个数为n的话,SG是n%2 + 1
然后bfs解决就可以了
/* ***********************************************
Author :kuangbin
Created Time :2013/8/15 13:25:56
File Name :F:\2013ACM练习\2013多校8\1003.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ;
bool g[MAXN][MAXN];
int move[][] = {{,},{,-},{-,},{,},{,},{,-},{-,},{-,-}};
bool used[MAXN][MAXN];
int n,m;
bool check(int x,int y)
{
if(x > && g[x-][y])return true;
if(x < n- && g[x+][y])return true;
if(y > && g[x][y-])return true;
if(y < m- && g[x][y+])return true;
if(x > && y > && g[x-][y-])return true;
if(x > && y < m- && g[x-][y+])return true;
if(x < n- && y > && g[x+][y-])return true;
if(x < n- && y < m- && g[x+][y+])return true;
return false;
}
int dfs(int x,int y)
{
queue<pair<int,int> >q;
q.push(make_pair(x,y));
int cnt = ;
used[x][y] = true;
while(!q.empty())
{
pair<int,int> tmp = q.front();
q.pop();
int nx = tmp.first;
int ny = tmp.second;
if(check(nx,ny))
{
cnt++;
continue;
}
for(int i = ;i < ;i++)
{
int tx = nx + move[i][];
int ty = ny + move[i][];
if(tx < || tx >= n || ty < || ty >= m)continue;
if(used[tx][ty])continue;
if(g[tx][ty])continue;
q.push(make_pair(tx,ty));
used[tx][ty] = true;
}
}
return cnt;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase ++;
int k;
scanf("%d%d%d",&n,&m,&k);
memset(g,false,sizeof(g));
int x,y;
while(k--)
{
scanf("%d%d",&x,&y);
g[x][y] = true;
}
memset(used,false,sizeof(used));
int ans = ;
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
if(!g[i][j] && !used[i][j] && !check(i,j))
{
int tmp = dfs(i,j);
ans ^= (tmp%+);
}
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
if(!g[i][j] && !used[i][j] && check(i,j))
ans ^= ;
if(ans == )printf("Case #%d: Fanglaoshi\n",iCase);
else printf("Case #%d: Xiemao\n",iCase);
} return ;
}
HDU 4678 Mine (2013多校8 1003题 博弈)的更多相关文章
- HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)
Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
- HDU 4704 Sum (2013多校10,1009题)
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- HDU 4699 Editor (2013多校10,1004题)
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 4696 Answers (2013多校10,1001题 )
Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- HDU 4691 Front compression (2013多校9 1006题 后缀数组)
Front compression Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Othe ...
- HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)
Prince and Princess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
随机推荐
- 《深入理解Java虚拟机》笔记--第三章 、垃圾收集器与内存分配策略
1960年诞生于MIT的Lisp是第一门真正使用内存动态分配和垃圾收集技术的语言. Java的垃圾收集(Garbage Collection)主要关注堆和方法区的内存回收. 在GC堆进行回收前,第一件 ...
- rcnn ->fast rcnn->faster rcnn物体检测论文
faster rcnn中的rpn网络: 特征可以看做一个尺度51*39的256通道图像,对于该图像的每一个位置,考虑9个可能的候选窗口:三种面积{1282,2562,5122}×三种比例{1:1,1: ...
- 连接数据库:ERROR:The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration prop
本打算在maven项目中配置mybatis试试看,想到mybatis如果不是在容器中运行,那么他的事务控制实际上可以使用的是jdbc的提交和回滚,这就要在pom.xml文件中配置mysql-conne ...
- 以太坊go-ethereum客户端(三)两种全节点启动模式
这篇博客介绍一下go-ethereum全节点的两种启动模式:主网络快速启动和测试网络快速启动.这也是客户端所提供的两种启动方式,直接拿来使用即可.下面具体介绍一下使用方法. 主网络快速启动 其实,我们 ...
- js实现静态页面跳转传参
最近有个项目: 存静态web服务,一个新闻页面列表出所有新闻摘要信息,然后通过点击新闻详情访问到该新闻的详情页面: 新闻展示的页面通过ajax请求接口获取到新闻的摘要信息,预计想通过id的方式访问到新 ...
- css3代码整理—弹性盒子篇
父级使用弹性盒子: #fu{ display:flex; } 父级中子级的对齐方式: 1.水平对齐方式:两端对齐 #fu { display:flex; justify-content:space-b ...
- TeX中的引号(UVa272)
问题: 在Tex中,做双引号的" `` ",右双引号是" '' "(两个回车左边的).输入一篇包含双引号的文章,你的任务是把它转换成TeX的格式. 样例输入: ...
- 为什么可以这么快! awk 与python的应用
这几天刚处理一个排序问题 源文件: 可以看到有11G大小,需要根据最后一列的热度来做一下排序.如果让你来做这样的排序,在linux环境下,你会如何处理呢? xch27@lanzhou:/asrdata ...
- 16.Spark Streaming源码解读之数据清理机制解析
原创文章,转载请注明:转载自 听风居士博客(http://www.cnblogs.com/zhouyf/) 本期内容: 一.Spark Streaming 数据清理总览 二.Spark Streami ...
- 在Linux中设置UMASK值
umask值用于设置用户在创建文件时的默认权限,当我们在系统中创建目录或文件时,目录或文件所具有的默认权限就是由umask值决定的. 对于root用户,系统默认的umask值是0022:对于普通用户, ...