codeforces 1383B 位运算

1383B 1900的题
题意:给你n个数,得分为你选的数的异或和,现在小明和小红进行博弈,小明先手,两人的选择都是最优的,问小明能否win
思路:我的想法是看了标程之后做出来的,首先对这n个数进行取异或和ans,如果ans=0那么就意味着,无论两人怎么取,最后的得分都是一样的。然后讨论ans!=0的情况,我们要知道对位的运算,肯定是你取到了最高位的你就肯定获胜了,所以对我们得到的ans进行位运算,从高位开始,如果有高位不等于0,那么对所有的数进行当前所在的位运算,因为只有当前位能对最终的结果造成影响,用一个数组f【2】进行存储,f【1】的值肯定是奇数,因为如果是偶数的话,ans在当前位的值一定是零,然后对这个f【1】的值进行讨论,当且仅当f【1】%4=3&&f【0】%2=0时,小红能获胜,其他情况都是小明获胜。因为只有这种情况小红能拿奇数个当前位,其他情况都拿不到。
最后的代码如下:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define fopen freopen("file.in","r",stdin);freopen("file.out","w",stdout);
#define fclose fclose(stdin);fclose(stdout);
#define PI 3.14159265358979323846
const int inf = 1e9;
const ll onf = 1e18;
const int maxn = 1e5+10;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int a[maxn];
inline void cf(){
    int t = read();
    while(t--){
        int n = read();
        int ans = 0;
        rep(i,0,n-1) a[i]=read(), ans^=a[i];
        if(ans==0){printf("DRAW\n");continue;}
        per(k,0,30){
            if(ans>>k&1){
                int f[2];f[0]=f[1]=0;
                for(int i = 0; i < n; i++){
                    f[a[i]>>k&1]++;
                }
                if(f[1]%4==3&&f[0]%2==0){
                    printf("LOSE\n");
                }else printf("WIN\n");
                break;
            }
        }
    }
    return ;
}
signed main(){
    cf();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值