Day11 - N - Game HDU - 3389

题目链接

题意是说有1到n个标号的盒子,选择一个非空的盒子A,B是否空无所谓,满足(A+B)%2=1,(A+B)%3=0,A>B

解上面的同余方程组,最小解为3,循环为2*3=6,那我们可以把前5个盒子对应能选择的盒子可以列举出来

1-2-8-14-20

2已经选过

3-6-12-

4-5-11-

5已经选过

那我们可以转换成3个独立的Nim游戏,因为转移物品和拿走物品是一样的,拿走的数量不设上限,则1、3、4盒子的状态是P,其对应的盒子标号对6取余分别为2、0、5,那我们就把对应的数量异或起来就行了

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

void run_case() {
    int n, ans = 0, t;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> t;
        if(i%6==0||i%6==5||i%6==2)
            ans ^= t;
    }
    if(ans) cout << ": Alice\n";
    else cout << ": Bob\n";
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t; cin >> t;
    for(int i = 1; i <= t; ++i) {
        cout << "Case " << i;run_case();
    }
    cout.flush();
    return 0;
}
View Code

 

posted @ 2020-02-20 17:47  GRedComeT  阅读(86)  评论(0编辑  收藏  举报