题解:P15320 【MX-X24-T1】「RiOI-7」Ah, It's Yesterday Once More

· · 题解

P15320题解

题目传送门

题目大意

给定 t 个长度为 n 的序列,每次取一个长度大于等于 2 的子集删除然后将此子集内最小不存在的自然数添加进序列中直到序列中只剩一个数为止。

若剩余元素为 0 则Alice赢否则Bob赢。

思路

可将除 0 以外所有的数看作 1 。

分类讨论:

  1. 当 n==1 时:若序列为:0 则Alice赢,否则Bob赢。

  2. 当 n==2 时:若序列中全为1,Alice只能合成 1,1 为 0 Alice必赢。反之Bob必赢。若序列为 0,1 合成为 1 Bob必赢。

  3. 当 n>=3 时:Alice若要赢则需让序列变为 1,1 而Bob要赢则需让序列变为 1,0 或 0,0 。

    已知当所选子集中有至少一个 0 时 mex=1 ,所以当序列中有至少一个 1 时Alice就可以将除了一个 1 以外剩余的 0 与 1 全一次性变成 1 构成 1,1 。特别的,当序列中全是 1 时,Alice可一次性将所有的 1 变成一个 0 赢下比赛

    像这样:

    {1,1,1,1,1,1,1,0,0}->{1}+{1,1,1,1,1,1,0,0}->{1,1}。

    {1,1,1,1,1}->{0}。

    否则Bob赢。

AC code

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[2];
signed main(){
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        a[0]=0;
        a[1]=0;
        int n;
        cin>>n;
        for(int i=1;i<=n;i++){
            int x;
            cin>>x;
            if(x==0){
                a[0]++;
            }else{
                a[1]++;
            }
        }
        if(n==1){
            if(a[0]){
                cout<<"Alice"<<endl;
            }else{
                cout<<"Bob"<<endl;
            }
        }else if(n==2){
            if(a[0]&&a[1]){
                cout<<"Bob"<<endl;
            }else if(a[0]){
                cout<<"Bob"<<endl;
            }else if(a[1]){
                cout<<"Alice"<<endl;
            }
        }else{
            if(a[1]>=1){
                cout<<"Alice"<<endl;
            }else{
                cout<<"Bob"<<endl;
            }
        }
    } 
    return 0;
}