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. Tomcat启动:Container StandardContext[] has not been started

    Container StandardContext[] has not been started\root.xml 初始化失败,检查数据源配置

  2. RPC框架实现思路浅析

    第一部分,设计分析 远程调用要解决的主要问题: 1,序列化 : 如何将对象转化为二进制数据进行传输,如何将二进制数据转化对象 2,数据的传输(协议,第三方框架) 3,服务的注册/发现,单点故障,分布式 ...

  3. SQL查询语句分类

    SQL查询语句有多种,下面总结下.首先先建三张表用于后面的实验 -- 学生表,记录学生信息 CREATE TABLE student( sno ), sname ), ssex ENUM('男','女 ...

  4. 编译安装httpd 2.4

    author:JevonWei 版权声明:原创作品 官方网站下载httpd2.4.apr及apr-util的相关软件包,并传输到centos 7系统中的/usr/local/src(apr1.6版本过 ...

  5. C语言中无符号数和有符号数之间的运算

    C语言中无符号数和有符号数之间的运算 C语言中有符号数和无符号数进行运算(包括逻辑运算和算术运算)默认会将有符号数看成无符号数进行运算,其中算术运算默认返回无符号数,逻辑运算当然是返回0或1了. un ...

  6. IOS学习[Swift中跳转与传值]

    Swift中页面跳转与传值: 1.简单方式 首先,Swift的跳转可分为利用xib文件跳转与storyboard跳转两种方法,我这里选择使用storyboard的界面跳转方法. 1.通过在storyb ...

  7. 微信公众平台接口调用第一步(获取access_token)

    最近公司需要开发微信公众号,闲着无聊就写写博客,希望能帮到你我 上代码: package test; import java.util.List; import java.util.ArrayList ...

  8. Color.js增强你对颜色的控制

    往逝之因 不要低头,皇冠会掉...  可你又没有皇冠 Color.js 增强你对颜色的控制 阅读目录 轻松管理颜色--color.js库 使用color.js Accessor Methods 你该知 ...

  9. (2)ES6解构赋值-数组篇

    1.解构赋值-数组篇 //Destrcturing(解构) //ES5 /* var a = 1; var b = 2; var c = 3; */ //ES6 var [a,b,c] = [1,2, ...

  10. 【深入Java虚拟机】之八:Java垃圾收集机制

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/18076173 对象引用 Java中的垃圾回收一般是在Java堆中进行,因为堆中几乎存放了J ...