HDU 5795 A Simple Nim

打表找SG函数规律。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} int sg[],f[]; int main()
{
sg[]=;
for(int i=;i<=;i++)
{
memset(f,,sizeof f); for(int j=;j<i;j++) f[sg[j]]=; for(int j=;j<=i;j++)
{
for(int k=;k<=i;k++)
{
for(int s=;s<=i;s++)
{
if(j+k+s!=i) continue;
f[sg[j]^sg[k]^sg[s]]=;
}
}
}
for(int j=;j<;j++) if(f[j]==) {sg[i]=j;break;}
}
for(int i=;i<=;i++) printf("i:%d sg[i]:%d\n",i,sg[i]);
return ;
}

HDU 5795 A Simple Nim

然后就可以轻松AC了...

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int T,n; LL ans,x; LL SG(LL x)
{
if(x==)return ; if(x==) return ;
if(x%==) return x-; if((x+)%==) return x+;
return x;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); ans=;
for(int i=;i<=n;i++) scanf("%lld",&x), ans=ans^SG(x);
if(ans) printf("First player wins.\n");
else printf("Second player wins.\n");
}
return ;
}
上一篇:PO、VO、BO、DTO、POJO、DAO


下一篇:JDOM 操作XML