Mine

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 352    Accepted Submission(s): 94

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,Yimeans 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

博弈题;用SG值做:

连通的空白块和相连的数字块是一起的,一个单独的数字块是一类。

单独一个的数组块,SG是1.

空白块+若干个数字块,数字块个数为n的话,SG是n%2 + 1

 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
#define ll long long int
int a[][];
int b[][];
int n,m;
int z[][];
void fun()
{
int i,j;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(a[i][j]==-)
{
for(int r=;r<;r++)
{
if(a[i+z[r][]][j+z[r][]]!=-)
a[i+z[r][]][j+z[r][]]++;
}
}
}
}
}
int dfs(int x,int y)
{
int i;
ll sum=;
queue<pair<int,int> >aa;
while(!aa.empty())aa.pop();
aa.push(make_pair(x,y));
while(!aa.empty())
{
int fx=aa.front().first;
int fy=aa.front().second;
aa.pop();
for(i=;i<;i++)
{
if(fx+z[i][]<=n&&fx+z[i][]>=)
if(fy+z[i][]<=m&&fy+z[i][]>=)
if(!b[fx+z[i][]][fy+z[i][]])
{
if(a[fx+z[i][]][fy+z[i][]]>)sum++;
else
aa.push(make_pair(fx+z[i][],fy+z[i][]));
b[fx+z[i][]][fy+z[i][]]=;
}
}
}
return sum%+;
}
int main()
{
int t;
scanf("%d",&t);
int i,j,r;
z[][]=;z[][]=;z[][]=;z[][]=;
z[][]=;z[][]=-;z[][]=-;z[][]=;
z[][]=;z[][]=;z[][]=;z[][]=-;
z[][]=-;z[][]=;z[][]=-;z[][]=-;
for(r=;r<t;r++)
{
int k,x,y;
scanf("%d%d%d",&n,&m,&k);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(j=;j<k;j++)
{
scanf("%d%d",&x,&y);
a[x+][y+]=-;
b[x+][y+]=;
}
fun();
int sum=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(a[i][j]==&&b[i][j]==)
b[i][j]=,sum^=dfs(i,j);
}
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(!b[i][j])
sum^=;
}
if(!sum)
printf("Case #%d: Fanglaoshi\n",r+);
else printf("Case #%d: Xiemao\n",r+);
}
}

hdu4678 Mine 2013 Multi-University Training Contest 8 博弈题的更多相关文章

  1. 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题

    I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 ...

  2. 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  3. HDU 4608 I-number 2013 Multi-University Training Contest 1 1009题

    题目大意:输入一个数x,求一个对应的y,这个y满足以下条件,第一,y>x,第二,y 的各位数之和能被10整除,第三,求满足前两个条件的最小的y. 解题报告:一个模拟题,比赛的时候确没过,感觉这题 ...

  4. 2016 Multi-University Training Contest 2 第一题Acperience

    Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Probl ...

  5. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  6. Integer Partition(hdu4658)2013 Multi-University Training Contest 6 整数拆分二

    Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  7. Partition(hdu4651)2013 Multi-University Training Contest 5

    Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Krak&#243;w

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  9. Partition(hdu4651)2013 Multi-University Training Contest 5----(整数拆分一)

    Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

随机推荐

  1. 搬家后Magento前台只有产品的缩略图不显示

    第一种可能:缓存不足 http://blog.csdn.net/ddjohn/article/details/6648199 最近发现一个怪异的现象,Magento前台只有产品的缩略图不显示.我检查了 ...

  2. 3DES 加解密,对长度不限制

    #region 3DES /// <summary> /// 3DES加密 /// </summary> /// <param name="strString& ...

  3. jQuery背景跟随鼠标移动的网页导航

    首页 PSD模板 CSS模板 特效插件 源码下载 酷站欣赏 建站资源 建站教程 心境之旅 在线留言 设为首页 加入收藏 我要投稿 联系站长 Search     首页 PSD模板 CSS模板 特效插件 ...

  4. bzoj1396

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1396 题目大意: 题解:后缀自动机,只出现一次,那么就是right值为1,那么对于一段1-- ...

  5. 详解JDBC连接数据库

    一.概念 1. 为了能让程序操作数据库,对数据库中的表进行操作,每一种数据库都会提供一套连接和操作该数据库的驱动,而且每种数据库的驱动都各不相同,例如mysql数据库使用mysql驱动,oracle数 ...

  6. Cloud Carousel

    <div class="carousel1" id="carousel1" > <a href="#"><im ...

  7. zigbee 中ZDO的理解

    ---恢复内容开始--- ZigBee     物理层:主要进行无线数据的收发,同时定义了无线传输的信道以及频率.      MAC层:使用CSMA-CA机制接入到无线信道,负责传输信标帧,保持同步和 ...

  8. tomcat使用spring-loaded实现应用热部署

    springloaded官方说明: Spring Loaded is a JVM agent for reloading class file changes whilst a JVM is runn ...

  9. python文件操作笔记

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.切换工作目录: os.c ...

  10. 关于DELL服务器如果采购散件,进行服务器升级的相关说明

    拿DELL服务器内存来说明这个情况,其他硬盘等等是 一样的: 1.DELL服务器的内存散件,从购买之日起,质保期是一年: 2.但是如果你把内存插到能兼容这个内存的服务器上去使用,请注意我的字眼,是能兼 ...