zoukankan      html  css  js  c++  java
  • HDU 5996 dingyeye loves stone ---BestCoder Round #90

    题目链接

    设根节点的深度为0,将所有深度为奇数的节点的石子数目xor起来,则先手必胜当且仅当这个xor和不为0。 证明同阶梯博弈。对于偶深度的点上的石子,若对手移动它们,则可模仿操作;对于奇深度上的石子,移动一次即进入偶深度的点。 时空复杂度O(n)

    用vector存搜一下就行。

    #include <cstdio>
    #include <iostream>
    #include <vector>
    #include <cstring>
    using namespace std;
    vector<int> v[100050];
    int num[100050];
    int ans;
    void dfs(int i,int d)
    {
        if(d&1) ans=ans^num[i];
        for(int j=0;j<v[i].size();j++)
        dfs(v[i][j],d+1);
    }
    int main()
    {
        int t,n,x;
        scanf("%d",&t);
        while(t--)
        {
            ans=0;
            scanf("%d",&n);
            memset(num,0,sizeof(num));
            for(int i=0;i<n;i++)
            v[i].clear();
            for(int i=1;i<n;i++)
            {
                scanf("%d",&x);
                v[x].push_back(i);
            }
            for(int i=0;i<n;i++)
            scanf("%d",&num[i]);
            dfs(0,0);
            if(ans) puts("win");
            else puts("lose");
        }
        return 0;
    }
  • 相关阅读:
    Linux
    python中元类
    POJ 1182 食物链
    POJ 1733 Parity game
    top 介绍
    周记 2014.8.31
    windows10配置python
    oracle执行update时卡死问题的解决办法
    An Easy Introduction to CUDA C and C++
    super()
  • 原文地址:https://www.cnblogs.com/Ritchie/p/6196582.html
Copyright © 2011-2022 走看看