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ó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. Appium环境搭建(python)

    appium是一个开源的,适用于原生或者移动网络和混合应用程序在 iOS 和 Android 平台上的的开源自动化测试框架.在这里,详细的介绍Appium的环境搭建步骤. 1.安装Node.js在ht ...

  2. 深度学习框架-caffe安装-环境[Mac OSX 10.12]

    深度学习框架-caffe安装 [Mac OSX 10.12] [参考资源] 1.英文原文:(使用GPU) [http://hoondy.com/2015/04/03/how-to-install-ca ...

  3. nhibernate教程(4)--条件查询(Criteria Query)

    NHibernate之旅(4):探索查询之条件查询(Criteria Query) 2008-10-16 18:20 by 李永京, 44341 阅读, 43 评论, 收藏,  编辑 本节内容 NHi ...

  4. oracle12之 多租户容器数据库架构

    解读: 这张幻灯片展示了三个被部署的应用程序的整合 三个不同的非cdbs成为一个单一的.幻灯片中的图形显示了一个多租户 容器数据库有四个容器:根和三个可插入的数据库.每一个 可插入数据库有它自己的专用 ...

  5. 跨浏览器tab页的通信解决方案尝试

    目标 当前页面需要与当前浏览器已打开的的某个tab页通信,完成某些交互.其中,与当前页面待通信的tab页可以是与当前页面同域(相同的协议.域名和端口),也可以是跨域的. 要实现这个特殊的功能,单单使用 ...

  6. 第二次作业——个人项目实战(Sudoku)

    Github:Sudoku 项目相关要求 利用程序随机构造出N个已解答的数独棋盘 . 输入 数独棋盘题目个数N 输出 随机生成N个 不重复 的 已解答完毕的 数独棋盘,并输出到sudoku.txt中, ...

  7. 2015级软工实践k班第一次作业-准备

    第一次作业-准备······ 几篇文章阅读下来发现一个事实,还是要有明确的目标,清楚自己需要做什么最为重要.然后根据目标确定需要为之所做的准备工作,考研也好,工作也罢,都是服务于自己的目标. 问题答应 ...

  8. [转载]请教各位高手光盘版或者U盘版的BT保存配置的问题

    这样安装的bt4默认是不能保存配置的,每次你更改了设置,下次重启又没有了.在网上下载一个叫做"saveFile.rar"的压缩包,大小40K左右,这个是bt4能够保存配置关键,当然 ...

  9. 201521123016 《Java程序设计》第13周学习总结

    1. 本周学习总结 2. 书面作业 1. 网络基础 1.1 比较ping www.baidu.com与ping cec.jmu.edu.cn,分析返回结果有何不同?为什么会有这样的不同? ping w ...

  10. 浅谈JAVA中“增强”类的某个方法的几个中方法!

    一.继承 使用场景:能够控制这个类的构造的时候,才可以使用继承. 优点:简单容易使用, 缺点:耦合性大大的增强,不利于后期的维护,所以对于继承这种方法,谨慎使用.  代码实现:二.装饰者模式 使用场景 ...