P4113

Nim游戏

建树,考虑公平组合游戏

对于一个点 \(SG(x)\),枚举它及它的子树,计算所有的后继状态,具体来说每个后继状态都是在这个子树中删除一条链,然后将分开的每一个子树的 \(SG\) 异或起来,这个值为这个子状态的 \(SG\)

然后 \(SG(x)=mex(SG(v))\)

特判最上面一层

// Author: xiaruize
#ifndef ONLINE_JUDGE
bool start_of_memory_use;
#endif
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
clock_t start_clock = clock();
#endif
#define int long long
#define ull unsigned long long
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define fir first
#define sz(a) int((a).size())
#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define mms(arr, n) memset(arr, n, sizeof(arr))
#define rep(i, a, n) for (int i = (a); i <= (n); ++i)
#define per(i, n, a) for (int i = (n); i >= (a); --i)
int max(int a, int b)
{
    if (a > b)
        return a;
    return b;
}
int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int N = 50 + 10;

int n;
struct node
{
    int x, y, r;
} s[N];
vector<int> g[N];
int sg[N];
int fa[N];
set<int> st;

bool cmp(node x, node y)
{
    return x.r < y.r;
}

void calc(int x, int val)
{
    for (auto v : g[x])
        val ^= sg[v];
    st.insert(val);
    for (auto v : g[x])
        calc(v, val ^ sg[v]);
}

void dfs(int x)
{
    // cerr << "flag" << x << endl;
    for (auto v : g[x])
        dfs(v);
    if (!x)
        return;
    st.clear();
    calc(x, 0);
    // cerr << x << endl;
    // for (auto v : st)
    //     cerr << v << ' ';
    // cerr << endl;
    while (st.find(sg[x]) != st.end())
        sg[x]++;
    // cerr << x << ' ' << sg[x] << endl;
}

void solve()
{
    cin >> n;
    rep(i, 1, n) cin >> s[i].x;
    cin >> n;
    rep(i, 1, n) cin >> s[i].y;
    cin >> n;
    rep(i, 1, n) cin >> s[i].r;
    sort(s + 1, s + n + 1, cmp);
    rep(j, 1, n)
    {
        rep(i, j + 1, n)
        {
            if ((s[i].x - s[j].x) * (s[i].x - s[j].x) + (s[i].y - s[j].y) * (s[i].y - s[j].y) <= (s[i].r - s[j].r) * (s[i].r - s[j].r))
            {
                g[i].push_back(j);
                fa[j] = i;
                break;
            }
        }
    }
    rep(i, 1, n) if (!fa[i]) g[0].push_back(i);
    dfs(0);
    // rep(i, 1, n) cerr << sg[i] << ' ';
    int res = 0;
    for (auto v : g[0])
    {
        res ^= sg[v];
    }
    if (res)
        cout << "Alice";
    else
        cout << "Bob";
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int testcase = 1;
    // cin >> testcase;
    while (testcase--)
        solve();
#ifndef ONLINE_JUDGE
    cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
    cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
    return 0;
}
posted @ 2024-04-02 17:00  xiaruize  阅读(33)  评论(0)    收藏  举报