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 ...
随机推荐
- <Learning How to Learn>Week One: Focused versus Diffuse Thinking
1-1 Introduction to the focused and diffuse modes (4:40) 两种思考的模式:focused mode以及diffuse mode focused ...
- tomcat 设置默认编码格式
在tomcat目录下 conf文件夹下的server.xml中: <Connector port="80" protocol="HTTP/1.1" ...
- Zookeeper + Hadoop + Hbase部署备忘
网上类似的文章很多,本文只是记录下来备忘.本文分四大步骤: 准备工作.安装zookeeper.安装hadoop.安装hbase,下面分别详细介绍: 一 准备工作 1. 下载 zookeeper.had ...
- [itint5]判断是否为二叉搜索树
http://www.itint5.com/oj/#25 这题在leetcode上是用中序遍历来做的,但是这里由于有相等的情况,即左子树小于等于根,这样中序遍历无法完全判定.可以用递归来做,用递归给出 ...
- 新的HTTP框架:Daraja Framework
https://www.habarisoft.com/daraja_framework.html
- MyBatis的两个配置文件
MyBatis有两个基本的配置文件,一个用来配置环境信息(mybatis.xml),一个用来写SQL语句(xxMapper.xml). mybatis.xml: <?xml version=&q ...
- 如何引用传递String Boolean 等,并改变他们的值
如何引用传递String Boolean 等,并改变他们的值 采用list, 在存入位置改变list的值 如 list.add(true); list.remove(0); list.add(fals ...
- ARM7ldr指令与ldr伪指令
ldr伪指令的第二个操作数之前有个=,意思是第一个操作书 = 第二个操作数,相当明了 核心就在于对于用.word指令在.text段里另外定义一段内存,用ldr r0,[pc + x(可以算出.text ...
- JS计算字符串所占字节数
最近项目有个需求要用js计算一串字符串写入到localStorage里所占的内存,众所周知的,js是使用Unicode编码的.而Unicode的实现有N种,其中用的最多的就是UTF-8和UTF-16. ...
- cf 189B - Counting Rhombi
题目:189B - Counting Rhombi http://codeforces.com/problemset/problem/189/B 题意:给定一个长方形的 矩形,求能在这个矩形里有多少 ...