HDU 5299 L - Circles Game 树上删边博弈

Circles Game



Problem Description
There are n circles on a infinitely large table.With every two circle, either one contains another or isolates from the other.They are never crossed nor tangent.
Alice and Bob are playing a game concerning these circles.They take turn to play,Alice goes first:
1、Pick out a certain circle A,then delete A and every circle that is inside of A.
2、Failling to find a deletable circle within one round will lost the game.
Now,Alice and Bob are both smart guys,who will win the game,output the winner's name.
 

Input
The first line include a positive integer T<=20,indicating the total group number of the statistic.
As for the following T groups of statistic,the first line of every group must include a positive integer n to define the number of the circles.
And the following lines,each line consists of 3 integers x,y and r,stating the coordinate of the circle center and radius of the circle respectively.
n≤20000,|x|≤20000,|y|≤20000,r≤20000。
 

Output
If Alice won,output “Alice”,else output “Bob”
 

Sample Input
  
  
2 1 0 0 1 6 -100 0 90 -50 0 1 -20 0 1 100 0 90 47 0 1 23 0 1
 

Sample Output
  
  
Alice Bob
 

Author
FZUACM

 
/*
 *  树上删边博弈
 *  在平面x-O-y上有很多圆,这些圆的位置关系只有内含和相离,先操作如下:
 *  除去一个圆同时除去其包含的所有圆,最后不能操作的人输
 *  抽象:直接包含圆是直接被包含圆的父节点,直接包含圆的所有直接被包含圆是兄弟
 *  为处理方便不至于构造出来的是森林,可将整个平面看成一个最大的圆,所有的圆都被直接或间接包含在其中
 */

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

const int MAXN = 20000 + 7;
int n;
vector<int> linker[MAXN]; // 邻接表

void Init() {
    for(int i = 0; i <= n; ++i) {
        linker[i].clear();
    }
}

struct Circle {
    int x, y, r;
    friend bool operator<(Circle& a, Circle& b) {
        return a.r < b.r;
    }
}cir[MAXN];

int getDis(Circle a, Circle b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y)*(a.y - b.y);
}

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

int main() {
    int T;
    cin >> T;
    while(T--) {
        Init();
        cin >> n;
        for(int i = 0; i < n; ++i) {
            cin >> cir[i].x >> cir[i].y >> cir[i].r;
        }
        sort(cir, cir + n);
        for(int i = 0; i < n; ++i) {
            bool hasSubCir = false;
            for(int j = i+1; j < n ; ++j) {
                // 内含关系,|r1 - r2| >= |o1 - o2|
                if((cir[j].r - cir[i].r) * (cir[j].r - cir[i].r) >= getDis(cir[i], cir[j])) {
                    hasSubCir = true;
                    linker[j].push_back(i);
                    break;
                }
            }
            if(!hasSubCir) {
                linker[n].push_back(i);
            }
        }
        cout << (dfs(n) ? "Alice" : "Bob") << endl;
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值