NOJ 1177 跳馬 SG函數,博弈
先貼個代碼,博弈問題還要繼續深究,special thanks to thinkking!原題:
Input
Output
SampleInput
2 5 2 2 2 2 3 5 2 3 3 2 3
SampleOutput
Case 1: Alice Case 2: Bob
#include<iostream>
#include<cmath>
using namespace std;
int n,m;
int dir[2][2]=
{
{-1,-2},
{-2,-1}};
bool god(int x,int y)
{
if(x<1||x>500||y<1||y>500)
return false;
return true;
}
int const maxn=510;
int SG[maxn][maxn];
struct node
{
int x,y;
}q[20020];
int v[3];
int main()
{
int ca;
scanf("%d",&ca);
int cn=0;
for(int i=1;i<=500;i++)
![]()
{
for(int j=1;j<=500;j++)
![]()
{
memset(v,0,sizeof(v));
for(int k=0;k<2;k++)
![]()
{
int nx=i+dir[k][0];
int ny=j+dir[k][1];
if(god(nx,ny))
![]()
{
v[SG[nx][ny]]=1;
}
}
for(int k=0;k<=2;k++)
![]()
{
if(v[k]==0)
![]()
{
SG[i][j]=k;
break;
}
}
}
}
while(ca--)
![]()
{
cn++;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d%d",&q[i].x,&q[i].y);
![]()
int ans=0;
for(int i=1;i<=m;i++)
![]()
{
ans^=SG[q[i].x][q[i].y];
}
if(ans)
printf("Case %d: Alice\n",cn);
else
printf("Case %d: Bob\n",cn);
}
return 0;
}
posted on 2010-07-13 20:48 abilitytao 閱讀(1511) 評論(3) 編輯 收藏 引用