HDU 4678 Mine SG博弈
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博弈的更多相关文章
- HDU 4678 Mine (2013多校8 1003题 博弈)
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 4678 Mine
HDU 4678 把点开空地时会打开的一大片区域看成一块,题目中说到,在一盘游戏 中,一个格子不可能被翻开两次,说明任意两块空地不会包含相同的格子. 那么就可以看成一个组合游戏. 当空地旁边没连任何数 ...
- HDU 1848(sg博弈) Fibonacci again and again
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- HDU 4678 Mine(博弈)
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...
- HDU 1536 S-Nim SG博弈
S-Nim Problem Description Arthur and his sister Caroll have been playing a game called Nim for som ...
- hdu 4678 Mine 博弈论
这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...
- hdu 4778 Gems Fight! 博弈+状态dp+搜索
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...
- HDU 1525 类Bash博弈
给两数a,b,大的数b = b - a*k,a*k为不大于b的数,重复过程,直到一个数为0时,此时当前操作人胜. 可以发现如果每次b=b%a,那么GCD的步数决定了先手后手谁胜,而每次GCD的一步过程 ...
- UVA12293 Box Game —— SG博弈
题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉 ...
随机推荐
- 【Educational Codeforces Round 37 B】 Tea Queue
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用一个队列来模拟排队就好. 队列放三元组(x,y,z) x表示人的下标,y和z分别表示进入和退出时间. 然后枚举时间从1到5000 ...
- codevs——T1337 银行里的迷宫
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 题目描述 Description 楚楚每一次都在你的帮助下过了一关又一关(比如他开宴会). ...
- Android开发之蓝牙(Bluetooth)操作(一)--扫描已经配对的蓝牙设备
版权声明:本文为博主原创文章,未经博主允许不得转载. 一. 什么是蓝牙(Bluetooth)? 1.1 BuleTooth是目前使用最广泛的无线通信协议 1.2 主要针对短距离设备通讯(10m) ...
- bind DNS搭建笔记
设置默认网关 偶尔会出现问题 route add default gw 192.168.0.1 .vim /etc/sysctl.conf 这里是重点 配置路由转发,路由开启等都要用到. # Cont ...
- CORS support in Spring Framework--官方
原文地址:https://spring.io/blog/2015/06/08/cors-support-in-spring-framework For security reasons, browse ...
- Noip 2016 Day1 题解
老师让我们刷历年真题, 然后漫不经心的说了一句:“你们就先做做noip2016 day1 吧” ...... 我还能说什么,,,,,老师你这是明摆着伤害我们啊2333333333 预计分数:100+2 ...
- OpenGL编程逐步深入(四)Shaders
OpenGl 中的 Shader在一些中文书籍或资料中都被翻译为"着色器", 单从字面意思也看不出Shader到底是什么,Shader实际上就是一段代码,用于完成特定功能的一个模块 ...
- Sub Thread to update main Thread (UI) 2
Sub Thread to update main Thread (UI) 2 Handler.post(somethread); Handler.sendMessage("Msg&quo ...
- 不允许 ASSIGNMENT 语句中包含 FOR XML 子句。
DECLARE @guidList NVARCHAR(max) SELECT @guidList=( CAST(OrderGUID AS nvarchar(max)) +',') FROM Order ...
- lslpp 总结
lslpp action 字段状态值: APPLY应用文件集 CLEANUP清理文件集进行 COMMIT提交文件集 REJECT拒绝指定文件集 status 字段状态值: 标识安装操作历史记录 ...