HDU-4678 Mine 博弈SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678
题意就不说了,太长了。。。
这个应该算简单博弈吧。先求联通分量,把空白区域边上的数字个数全部求出来a[i](就是一个连通分量),然后就是n堆石子,每堆每次可以取一个或者全部取掉,然后要注意在取玩边上的石子后,剩下的就只能一次取掉了,因此我们直接把空白区域上的算做一个a[i]+1。然后这个SG函数很好求,奇数是1,偶数是2。。。
//STATUS:C++_AC_156MS_4268KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const LL MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e50;
const int dx[]={-,-,,,,,,-};
const int dy[]={,,,,,-,-,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int g[N][N];
int T,n,m,k; int bfs(int x,int y)
{
int i,nx,ny,ret=;
pii t;
g[x][y]=-;
queue<pii> q;
q.push(make_pair(x,y));
while(!q.empty())
{
t=q.front();q.pop();
for(i=;i<;i++){
nx=t.first+dx[i];
ny=t.second+dy[i];
if(nx<||nx>=n || ny<||ny>=m || g[nx][ny]==-)continue;
if(g[nx][ny])ret++;
else q.push(make_pair(nx,ny));
g[nx][ny]=-;
}
}
return ret;
} int main(){
// freopen("in.txt","r",stdin);
int i,j,sg,x,y,nx,ny,ca=;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
mem(g,);
for(i=;i<k;i++){
scanf("%d%d",&x,&y);
g[x][y]=-;
for(j=;j<;j++){
nx=x+dx[j];ny=y+dy[j];
if(nx<||nx>=n || ny<||ny>=m || g[nx][ny]==-)continue;
g[nx][ny]=;
}
} sg=;
for(i=;i<n;i++){
for(j=;j<m;j++){
if(g[i][j])continue;
sg^=(bfs(i,j)&)+;
}
}
for(i=;i<n;i++){
for(j=;j<m;j++){
if(g[i][j]==-)continue;
sg^=;
}
} printf("Case #%d: %s\n",ca++,sg?"Xiemao":"Fanglaoshi");
}
return ;
}
HDU-4678 Mine 博弈SG函数的更多相关文章
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
- HDU 4678 Mine(博弈)
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)
Fibonacci again and again Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & ...
- hdu 5795 A Simple Nim 博弈sg函数
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- 尼姆博弈+SG函数
博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...
- hdu_1848_Fibonacci again and again(博弈sg函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢 题解:SG函数模版题 ...
- HDU 5724 Chess(SG函数+状态压缩)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...
- HDU 5724 Chess(SG函数)
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
随机推荐
- _CrtIsValidPointer 问题
从微软站点: 检查指针有效性下面的示例使用 _CrtIsValidPointer 验证给定的内存范围对于读或写是否有效. _ASSERTE(_CrtIsValidPointer( address, s ...
- VS2005 VS2008 Manifest 配置问题总结
一.问题 编译某个遗留工程后,运行程序时报错,“由于应用程序的配置不正确,应用程序无法启动.重新安装应用程序可能会解决这个问题.” 查看生成的Manifest文件如下: <?xml versio ...
- JSON用法简介
[JSON简介] jsoncpp 主要包含三种类型的 class:Value.Reader.Writer.jsoncpp 中所有对象.类名都在 namespace Json 中,包含 json.h 即 ...
- define中的:#,##,#@
[define中的:#,##,#@] #define Conn(x,y) x##y #define ToChar(x) #@x #define ToString(x) #x (2)x##y表示什么?表 ...
- iOS开发之loadView、viewDidLoad及viewDidUnload的关系
iOS开发之loadView.viewDidLoad及viewDidUnload的关系 iOS开发之loadView.viewDidLoad及viewDidUnload的关系 标题中所说的3个方 ...
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-006-Pizza例子的支付流程
一. 1. 2.payment-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow x ...
- inflate方法与findViewById的区别
LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来找 re ...
- photoshop:制作木板木纹
1.设置颜色为木头相近颜色 2.滤镜->渲染->云彩 3.滤镜->杂色->添加杂色 4.滤镜->模糊->动感模糊 5.用矩形选取选取某块区域 6.滤镜->扭曲 ...
- IDirect3DDevice9::GetRenderTargetData
翻译自DXSDK 将渲染目标数据从设备内存拷贝到系统内存. HRESULT GetRenderTargetData( [in] IDirect3DSurface9 *pRenderTarget, ...
- 安装Hadoop系列 — eclipse plugin插件编译安装配置
[一].环境参数 eclipse-java-kepler-SR2-linux-gtk-x86_64.tar.gz //现在改为eclipse-jee-kepler-SR2-linux-gtk-x86_ ...