题解:B4227 [常州市程序设计小能手 2024] 游戏

· · 题解

题目

小 H:使最后两个数相同,要把所有个数 < 2 的数全部去掉,使其他的数个数都 \ge 2。

小 Y:使最后两个数不相同,要把所有个数 \ge 2 的数全部去掉,只剩 1 个,使其他的数个数都 < 2。

那么,我们把小 Y 需要去掉的数算出来,记为 ans。

每个人只能取 n-1 次,那么如果 ans>n-1,小 Y 就取不完了,此时输出 Lose,否则输出 Win。

代码:

#include<bits/stdc++.h>
#define int long long
#define double long double
#define debug(x) cout<<#x<<"->"<<x<<endl<<flush
#define endl '\n'
#define inf INT_MAX 
using namespace std;
const int N=1e7+7;
const int M=1e6+7;
const int mod=1e9+7;
const double eps=1e-6;
signed main(){
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    cin >>t;
    while(t--){
        int n;
        cin >>n;
        map<int,bool>m;
        int ans=0;
        for(int i=0;i<2*n;i++){
            int x;cin >>x;
            if(m[x])ans++;//之前就有过这个数,数量 >=2,ans 加一
            m[x]=1;//有过这个数了
        }
        if(ans>n-1){//小 Y 取不完,输了
            cout<<"Lose"<<endl;
        }else{//小 H 取不完,赢了
            cout<<"Win"<<endl;
        }
    }
    return 0;
}