HDU 5299 Circles Game(树的删边游戏)

题目链接:传送门 


题意:

给定你n个圆环,每两个圆要么包含要么相离,删除一个圆也要删除它包含的圆,最后不能删的人输。


分析:

树的删边游戏
规则如下:
l. 给出一个有 N 个点的树,有一个点作为树的根节点。
2. 游戏者轮流从树中删去边,删去一条边后,不与根节点相连的部分将被移走。
3. 谁无路可走谁输。
我们有如下定理:
[定理]
叶子节点的 SG 值为 0;

中间节点的 SG 值为它的所有子节点的 SG 值加 1 后的异或和。

然后这道题目就根据包含关系建一颗树,剩下的就是一个树的删边游戏。


代码如下:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int maxn = 20010;

vector<int > vc[maxn];

struct cir{
    int x,y,r;
    bool operator <(const cir &tmp)const{
        return r<tmp.r;
    }
    int dis(const cir &tmp){
        return (x-tmp.x)*(x-tmp.x)+(y-tmp.y)*(y-tmp.y);
    }
}c[maxn];

void init(){
    for(int i=0;i<maxn;i++)
        vc[i].clear();
}


int dfs(int u){
    int ret = 0;
    for(int i=0;i<vc[u].size();i++){
        int v = vc[u][i];
        ret^=dfs(v)+1;
    }
    return ret;
}

int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--){
        init();
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].r);
        }
        sort(c,c+n);
        for(int i=0;i<n;i++){
            bool tag = 0;
            for(int j=i+1;j<n;j++){
                if(c[i].dis(c[j])<=(c[j].r-c[i].r)*(c[j].r-c[i].r)){
                    tag=1;
                    vc[j].push_back(i);
                    break;
                }
            }
            if(!tag)
                vc[n].push_back(i);
        }
        int ans = dfs(n);
        if(!ans) puts("Bob");
        else puts("Alice");
    }
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值