http://acm.hdu.edu.cn/showproblem.php?pid=4678

自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG

这里子游戏之间没有影响所以只要找规律得出所有子游戏的SG值 然后求XOR就行了

这里题面太复杂 但看懂以后其实可以转换成取石子游戏:

给你N堆石子 , 每次只能取一个或者整堆取走 谁先取完谁胜

每堆石子的数量就是空白部分附近所有连接数字的数量+1(空白本身算一个石子)

孤立的单个数字也组成一堆

那么根据找规律可得:

奇数堆SG = 1 偶数堆SG = 2

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN 1005
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define DINF (1e10)
#define LINF ((1LL)<<50)
#define INF ((int)1e10)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define line cout<<"--------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// int gcd(int a,int b){ return b?gcd(b,a%b):a; }
// int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/ int ma[MAXN][MAXN];
bool vis[MAXN][MAXN];
int ax[] = {-,-,-,,,,,};
int ay[] = {-,,,-,,-,,};
int SG[MAXN*MAXN];
int n,m,k;
int check(int xx,int yy){
if(xx >= && xx < n && yy >= && yy < m) return true;
return false;
}
int bfs(pair<int,int> s){
queue< pair<int,int> > q;
int ct = ;
q.push(s);
while(!q.empty()){
for(int i = ; i < ; i++){
int xx = q.front().first + ax[i];
int yy = q.front().second + ay[i];
if(check(xx,yy)){
if(ma[xx][yy] == && !vis[xx][yy])
q.push(make_pair(xx,yy));
else if(ma[xx][yy] == && !vis[xx][yy])
ct++;
vis[xx][yy] = true;
}
}
q.pop();
}
return ct;
}
int main()
{
//FIN;
//FOUT;
int T;
cin>>T;
for(int cas = ; cas <= T; cas++){
memset(ma,,sizeof(ma));
memset(vis,false,sizeof(vis));
memset(SG,,sizeof(SG));
scanf("%d%d%d",&n,&m,&k);
for(int ck = ; ck < k ; ck++){
int a,b;
scanf("%d%d",&a,&b);
ma[a][b] = ;
for(int i = ; i < ; i++){
if(check(a+ax[i],b+ay[i]) && ma[a+ax[i]][b+ay[i]] != )
ma[a+ax[i]][b+ay[i]] = ;
}
}
int cnt = ;
for(int i = ; i < n ; i++){
for(int j = ; j < m ; j++){
if(ma[i][j] == && !vis[i][j]){
vis[i][j] = true;
SG[cnt++] = (bfs(make_pair(i,j)) + ) % == ? : ;
}
}
}
for(int i = ; i < n ; i++){
for(int j = ; j < m ; j++){
if(ma[i][j] == && !vis[i][j]){
vis[i][j] = true;
SG[cnt++] = ;
}
}
}
int res = SG[];
for(int i = ; i < cnt ; i++){
res = res ^ SG[i];
}
if(res == ) printf("Case #%d: Fanglaoshi\n",cas);
else printf("Case #%d: Xiemao\n",cas);
}
return ;
}

HDU 4678 Mine SG博弈的更多相关文章

  1. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  2. hdu 4678 Mine

    HDU 4678 把点开空地时会打开的一大片区域看成一块,题目中说到,在一盘游戏 中,一个格子不可能被翻开两次,说明任意两块空地不会包含相同的格子. 那么就可以看成一个组合游戏. 当空地旁边没连任何数 ...

  3. HDU 1848(sg博弈) Fibonacci again and again

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  4. HDU 4678 Mine(博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  5. HDU 1536 S-Nim SG博弈

    S-Nim Problem Description   Arthur and his sister Caroll have been playing a game called Nim for som ...

  6. hdu 4678 Mine 博弈论

    这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...

  7. hdu 4778 Gems Fight! 博弈+状态dp+搜索

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...

  8. HDU 1525 类Bash博弈

    给两数a,b,大的数b = b - a*k,a*k为不大于b的数,重复过程,直到一个数为0时,此时当前操作人胜. 可以发现如果每次b=b%a,那么GCD的步数决定了先手后手谁胜,而每次GCD的一步过程 ...

  9. UVA12293 Box Game —— SG博弈

    题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉 ...

随机推荐

  1. @property 的本质是什么?

    将访问.变量.访问控制进行了绑定:编译器负责自动合成. @dynamic:不会自动合成成员变量和存取方法. @property 的本质是什么?@property = ivar + getter + s ...

  2. 手把手教你进行R语言的安装及安装过程中相关问题解决方案

    这篇文章旨在为R语言的新手铺砖引路,行文相对基础,希望对在R语言安装上有问题的小伙伴提供帮助和指引.一.什么是 R 语言R 编程语言被广泛应用在统计科学和商业领域. 在各种编程语言排名中 R 语言的排 ...

  3. java反射与多态(父类调用子类)的代码演示

    package Test0817; import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method ...

  4. 三维偏序(陌上花开) CDQ分治

    十分巧妙. Code: #include <cstdio> #include <algorithm> #include <cstring> #define setI ...

  5. [JSOI2018]潜入行动 树形DP_复杂计数

    code #include <cstdio> #include <algorithm> #include <cstring> #include <string ...

  6. HTML5的核心内容

    开发者可以放心地使用html5的理由 兼容性.HTML5在老版本的浏览器可以正常运行,同时支持HTML5的新浏览器也能正常运行HTML4,用HTML4创建出来的网站不是必须全部重建的. 实用性.HTM ...

  7. Python3 利用POP3与smtplib进行计算机远程控制

    初习,代码有不足之处,欢迎指出. 跟大家分享的是,通过发送端发送cmd命令,从而对接收端进行cmd命令的控制. #接收端代码 from poplib import POP3 import time,o ...

  8. Ural 1303 Minimal Coverage(贪心)

    题目地址:Ural 1303 先按每一个线段的左端点排序,然后设置一个起点s.每次都从起点小于等于s的线段中找到一个右端点最大的. 并将该右端点作为新的起点s,然后继续找. 从左到右扫描一遍就可以. ...

  9. centos7;windows下安装和使用spice

    感谢朋友支持本博客,欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载,请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  10. 在SSM框架中我设置拦截器filter不能通过注解获取到实现类

    我在用注解注入实现类的时候,出现了这样的错误:如以下截图: 这个地方报出的错误是说明我的一个接口类型的类没有获取到,后来我就想要是我的实现类没有获取到那么我就直接new一个实现类然后再进行调用就会出现 ...