HihoCoder - 1172 SG函数应用
原文讲解很nice,我尝试换种观点
设背面朝上为F,否则T,
那么局面FFFFFF肯定为0
局面FTFFFF可以转为上面局面0,设为1
局面FFTFFF可以转到0,1,设为2
子游戏SG(x)=x
对于游戏和TTFTFFTF
我们可以分解为局面1,2,4,7的子游戏
然后SG求和就好,所以形式上和nim无异
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e6+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,r,c;
char str[maxn];
int main(){
while(cin>>n){
s1(str);
ll t=0;
rep(i,1,n){
if(str[i]=='H')t^=i;
}
if(t) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
return 0;
}

浙公网安备 33010602011771号