hdu 5299 Circles Game

Circles Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 547    Accepted Submission(s): 150



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

题意:在坐标系中给出一些圆,这些圆可能相互包含和相离,现在两个人玩一个游戏,每个人每次选择去掉一个圆,如果这个圆中有小圆,同时去掉,没有圆可取的人输。

分析:等级制的威佐夫博奕
因为圆与圆有相互包含的关系,那么我们可以建一棵树,虚设一个无穷大的圆作为根节点,那么剩下的圆与大圆建立联系。
比如例2的树:
<span style="font-size:18px;">    
        
            0
          /   \
         1     4
        / \   / \
       2   3 5   6

</span>



那么每一个子树进行威佐夫博奕,将结果传给父节点继续博弈,最终大圆的根节点博弈结果就是答案

<span style="font-size:18px;">#include<cstring>
#include<string>
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<vector>

using namespace std;

#define INF 0x3f3f3f3f

struct node
{
    int x,y;
    int r;
    int val;

    bool operator < (const node &A) const
    {
        return r>A.r;
    }
} T[20004];
vector<int>vec[20004];

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

    T[0].x=0;
    T[0].y=0;
    T[0].r=100000;
    T[0].val=0;
}

bool include(int k,int num)
{
    long long dis=(T[k].x-T[num].x)*(T[k].x-T[num].x)+(T[k].y-T[num].y)*(T[k].y-T[num].y);
    if(dis<=T[k].r*T[k].r) return true;
    return false;
}

void dfs_find(int k,int num)
{
    for(int i=0; i<vec[k].size(); i++)
    {
        if(include(vec[k][i],num))
        {
            dfs_find(vec[k][i],num);
            return ;
        }
    }
    vec[k].push_back(num);
    return ;
}

int dfs_solve(int k)
{
    int ans=0;
    for(int i=0;i<vec[k].size();i++)
    {
        ans^=dfs_solve(vec[k][i]);
    }
    T[k].val+=ans;
    return T[k].val;
}

int main()
{
    int T_T;
    scanf("%d",&T_T);

    while(T_T--)
    {
        int n;
        scanf("%d",&n);
        init(n);

        for(int i=1; i<=n; i++)
        {
            scanf("%d%d%d",&T[i].x,&T[i].y,&T[i].r);
            T[i].val=1;
        }

        sort(T+1,T+n+1);
        for(int i=1; i<=n; i++)
        {
            dfs_find(0,i);
        }

        dfs_solve(0);

        if(T[0].val!=0) printf("Alice\n");
        else printf("Bob\n");
    }
    return 0;
}
</span>



你可能感兴趣的:(hdu 5299 Circles Game)