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. 浅读K-means

    百度百科释义为 K-means算法是硬聚类算法,是典型的基于原型的目标函数聚类方法的代表,它是数据点到原型的某种距离作为优化的目标函数,利用函数求极值的方法得到迭代运算的调整规则.K-means算法以 ...

  2. 【DDD】领域驱动设计实践 —— 框架实现

    本文主要了在社区服务系统(ECO)中基于SpringMVC+mybatis框架对DDD的落地实现.本文为系列文章中的其中一篇,其他内容可参考:通过业务系统的重构实践DDD. 框架实现图 该框架实现基本 ...

  3. el-input监听不了回车事件

    vue使用element-ui的el-input监听不了回车事件,原因应该是element-ui自身封装了一层input标签之后,把原来的事件隐藏了,所以如下代码运行是无响应的: <el-inp ...

  4. Cookie中的HttpOnly详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt377 1.什么是HttpOnly? 如果您在cookie中设置了HttpOn ...

  5. ButterKnife的安装与使用以及ButterKnife右键不显示的大坑

    作为从安卓的的入门选手,第一次看到还以为是个第三方呢,从github下来之后感觉不对啊,这么多东西,后来一搜原来是个插件,而且不用从github上下载. 安装的方法很简单. 第一步:打开安卓studi ...

  6. cocos2dx lua中异步加载网络图片,可用于显示微信头像

    最近在做一个棋牌项目,脚本语言用的lua,登录需要使用微信登录,用户头像用微信账户的头像,微信接口返回的头像是一个url,那么遇到的一个问题就是如何在lua中异步加载这个头像,先在引擎源码里找了下可能 ...

  7. (转)C语言malloc()与free()的使用

    如何使用 malloc 函数 本文为转载内容,原文地址请点击 不要莫名其妙,其实上面这段小小的对话,就是malloc的使用过程.malloc是一个函数,专门用来从堆上分配内存.使用malloc函数需要 ...

  8. MFS文件系统的组成

    1.  元数据服务器.在整个体系中负责管理管理文件系统,目前MFS只支持一个元数据服务器master,这是一个单点故障,需要一个性能稳定的服务器来充当.希望今后MFS能支持多个master服务器,进一 ...

  9. 201521123067 《Java程序设计》第7周学习总结

    201521123067 <Java程序设计>第7周学习总结 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 Q1.ArrayList代码分析 ...

  10. 201521123110《Java程序设计》第11周学习总结

    1. 本周学习总结 2. 书面作业 1.互斥访问与同步访问 1.1 除了使用synchronized修饰方法实现互斥同步访问,还有什么办法实现互斥同步访问(请出现相关代码)? 1.2 同步代码块与同步 ...