牛牛爱博弈

题意

有一堆石头 (n) 个,两个人轮流取,每次只能取: (1,2,4,...,2^k) 个,取走最后一颗石头的人获胜。

题目链接:https://ac.nowcoder.com/acm/contest/6885/C

分析

(P/N) 分析打表找规律。

(n) (1) (2) (3) (4) (5) (6) (7)
P/N P P N P P N P

可知,当 (n\%3==0) 时,先手输。否则,后手输。

代码

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        if(n%3) printf("Alan
");
        else printf("Frame
");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/1024-xzx/p/13507884.html