hdu-4678-sg
Mine
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1731 Accepted Submission(s): 501
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
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define mp make_pair
#define pii pair<int,int>
int n,m,tot;
int e[][];
bool vis[][];
int fx[][]={-,,,,,-,,,-,-,-,,,-,,};
void bfs(int x,int y){
queue<pair<int,int> >q;
q.push(mp(x,y));
while(!q.empty()){
pii tmp=q.front();
q.pop();
if(vis[tmp.first][tmp.second]) continue;
vis[tmp.first][tmp.second]=;
if(e[tmp.first][tmp.second]==) {tot++;continue;}
for(int i=;i<;++i){
int dx=tmp.first+fx[i][];
int dy=tmp.second+fx[i][];
if(dx<||dy<||dx>n||dy>m||vis[dx][dy]) continue;
q.push(mp(dx,dy));
}
}
}
int main(){
int t,i,j,k,cas=;
cin>>t;
while(t--){
memset(vis,,sizeof(vis));
memset(e,,sizeof(e));
cin>>n>>m>>k;
int x,y;
while(k--){
scanf("%d%d",&x,&y);
x++;
y++;
vis[x][y]=;
e[x][y]=;
for(i=;i<;++i){
int dx=x+fx[i][];
int dy=y+fx[i][];
if(dx>&&dy>&&dx<=n&&dy<=m&&vis[dx][dy]==) e[dx][dy]=;
}
}
int sg=;
for(i=;i<=n;++i){
for(j=;j<=m;++j){
if(vis[i][j]||e[i][j]==) continue;
tot=;
bfs(i,j);
sg^=(tot%+);
}
}
for(i=;i<=n;++i)
for(j=;j<=m;++j)
if(!vis[i][j]&&e[i][j]==) sg^=;
printf("Case #%d: ",++cas);
sg?puts("Xiemao"):puts("Fanglaoshi");
}
return ;
}
hdu-4678-sg的更多相关文章
- hdu 4678 Mine
HDU 4678 把点开空地时会打开的一大片区域看成一块,题目中说到,在一盘游戏 中,一个格子不可能被翻开两次,说明任意两块空地不会包含相同的格子. 那么就可以看成一个组合游戏. 当空地旁边没连任何数 ...
- hdu 5724 SG+状态压缩
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 4678 Mine SG博弈
http://acm.hdu.edu.cn/showproblem.php?pid=4678 自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG 这里子游戏之间没有影响 ...
- hdu 2147 SG函数打表(手写也可以) 找规律
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others) Total ...
- HDU 1848 SG函数博弈
Fibonacci again and again Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1 ...
- hdu 3032 sg打表找规律 *
有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...
- HDU 1536 sg函数
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 4678 Mine 博弈论
这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...
- hdu 1536 SG函数模板题
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- hdu 4678
HDU 4768: Flyer 题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2... && A+k*C <= B).题目保证 ...
随机推荐
- 使用echo命令清空tomcat日志文件
使用echo命令清空日志文件echo -n "" > /server/tomcat/logs/catalina.out ==>要加上"-n"参数,默 ...
- C/C++笔记 #035# Makefile
相关资料: Understanding roles of CMake, make and GCC GCC and Make ( A simple tutorial, teaches u how to ...
- Python学习笔记之在Python中实现单例模式
有些时候你的项目中难免需要一些全局唯一的对象,这些对象大多是一些工具性的东西,在Python中实现单例模式并不是什么难事.以下总结几种方法: 使用类装饰器 使用装饰器实现单例类的时候,类本身并不知道自 ...
- Charles手机端抓包--证书
应用测试: Charles通过无线对手机进行抓包 测试系统: ubuntu 16.04 LTS 测试手机: IOS 10.3(14E277) Charles版本: Charles 4.1.4 手机证书 ...
- [矩阵十题第七题]vijos 1067 Warcraft III 守望者的烦恼 -矩阵快速幂
背景 守望者-warden,长期在暗夜精灵的的首都艾萨琳内担任视察监狱的任务,监狱是成长条行的,守望者warden拥有一个技能名叫“闪烁”,这个技能可以把她传送到后面的监狱内查看,她比较懒,一般不查看 ...
- ubuntu下交叉编译imagemagick
环境:ubuntu16.04 交叉编译器版本号:4.8.3 在编译之前要编译以下其依赖的软件或库:freetype,libpng,libxml2,libtiff,libjpeg,zlib,graphv ...
- 可持久化fhq-treap学习笔记
目录 可持久化fhq-treap----- 支持查询历史版本的非旋treap 先看看为啥他可以可持久化 过程 别的 注意&&出错&&吐槽 模板->luoguP38 ...
- 奇怪的分式|2014年蓝桥杯B组题解析第六题-fishers
奇怪的分式 上小学的时候,小明经常自己发明新算法.一次,老师出的题目是: 1/4 乘以 8/5 小明居然把分子拼接在一起,分母拼接在一起,答案是:18/45 (参见图1.png) 老师刚想批评他,转念 ...
- <OFFER> 06_PrintListInReversedOrder
#include<stack> #include "List.h" void PrintListReversingly_Iteratively(ListNode* pH ...
- Open Source Log Management
https://www.elastic.co/solutions/logging The Elastic Stack (sometimes known as the ELK Stack) is the ...