F - Grab The Tree HDU - 6324

https://vjudge.net/contest/310812#problem/F

给定一棵n 个点的树,每个点有权值。两个人玩游戏,先
手需要占领若干不相邻的点,然后后手占领剩下所有点。
每个人的得分为占领的点权异或和,分高的获胜。问最优策
略下游戏的结果。
1 ≤ n ≤ 105。
Shortest judge solution: 235 bytes

### 思路
并不能算是博弈的题
分析后手最好的结果就是平局,不可能获胜的

sum 为所有点权的异或和,A 为先手得分,B 为后手得分。
1)sum = 0只能是平局
2)sum不为零 二进制下最高位1
若先手拿走任意一个那一位为1 的点,则B 该位为0 A必胜

### 代码

#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <stack>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <iterator>
#include <set>
#include <map>
#include <utility>
#include <iomanip>
#include <ctime>
#include <sstream>
#include <bitset>
#include <deque>
#include <limits>
#include <numeric>
#include <functional>

#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define sort(a,n,int) sort(a,a+n,less<int>())
#define fread() freopen("in.in","r",stdin)
#define fwrite() freopen("out.out","w",stdout)
using namespace std;

typedef long long ll;
typedef char ch;
typedef double db;  

const int maxn=1e5+10;
//ll a[maxn];
int aa[maxn];

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else gcd(b,a%b);
}

int main()
{
    int t, n;
    cin >> t;
    int w[maxn] = {0}, u[maxn] = {0}, v[maxn] = {0};
    int flag = 0;
    int ans = 0;
    
    while(t--) {
        cin >> n;
        for(int i = 0; i < n; i++)        cin >> w[i];
        for(int i = 0; i < n-1; i++)    cin >> u[i] >> v[i];
        for(int i = 0; i < 32; i++){
            ans = 0;
            for (int j = 0; j < n; j++){
                if (w[j] & 1)ans++;
                w[j] >>= 1;
            }
            if (ans & 1){
                flag = 1;
                break;
            }
        }
        if (flag)    cout<<'Q'<<endl;
        else        cout<<'D'<<endl;
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/SutsuharaYuki/p/11224184.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值