题目链接: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函数的更多相关文章

  1. hdu 3032(博弈sg函数)

    题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...

  2. HDU 4678 Mine(博弈)

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

  3. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  4. HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

    Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & ...

  5. hdu 5795 A Simple Nim 博弈sg函数

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Pro ...

  6. 尼姆博弈+SG函数

    博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...

  7. hdu_1848_Fibonacci again and again(博弈sg函数)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢 题解:SG函数模版题 ...

  8. HDU 5724 Chess(SG函数+状态压缩)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...

  9. HDU 5724 Chess(SG函数)

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

随机推荐

  1. 安装ADT Cannot complete the install because one or more required items could not be found.

    点击进行安装,将会弹出 错误提示是: Cannot complete the install because one or more required items could not be found ...

  2. Nagios : Verifying Your Configuration

    Every time you modify your configuration files, you should run a sanity check on them. It is importa ...

  3. struts2 标签的使用之一 s:if

    struts2 的web 项目中为了方便的编写jsp,标签是最好的选择 1:struts2 标签库的定义在**-core-版本号.jar META-INF 路径下找到struts-tags.tld文件 ...

  4. HDU4502吉哥系列故事——临时工计划

    http://acm.hdu.edu.cn/showproblem.php?pid=4502 题意 :这个是中文题,我就不再详述了. 思路 : 以前做过一个活动区间选择,结果就按着那个思路敲了,后来发 ...

  5. Android 图片旋转(使用Matrix.setRotate方法)

    imageView2 = (ImageView) findViewById(R.id.img2); Bitmap bitmap = BitmapFactory.decodeResource(getRe ...

  6. jmeter 启用gzip压缩——解决测试中web服务器上行流量过大的问题

    最近测了几个前端的项目,发现它们都有一个共同点:应用所在服务器的网卡上行(trans)非常大——经常是 117 MB/S,这已经逼近了千兆网卡的极限了.下面记录下排查和解决过程: 一. jmeter ...

  7. 你不知道的pogo pin连接器

    pogo pin连接器是一种带弹簧的探针式连接器,pogo pin连接器结构看起来非常简单,但其制造工艺要求极其的精细与复杂,从车床加工,电镀,组装等每道工序,如果没有一个有良好品质控制和完善的制造水 ...

  8. POJ2531——Network Saboteur(随机化算法水一发)

    Network Saboteur DescriptionA university network is composed of N computers. System administrators g ...

  9. 获取html上元素的真正坐标

    使用HTML元素的style.left,style.top,style.width,style.height以及width,height属性,都不能获得元素的真正位置与大小,这些属性取出来的都是原来的 ...

  10. 新版本的tlplayer for android ,TigerLeapMC for windows发布了

    tlplayer for android 新版本修正了图像倾斜等等问题,增加了动态水印功能. 支持hls(m3u8),http,rtsp,mms,rtmp等网络协议. 声明tlplayer 上的变速不 ...