HDOJ 5299 Circles Game 圆嵌套+树上SG

Posted liguangsunls

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDOJ 5299 Circles Game 圆嵌套+树上SG相关的知识,希望对你有一定的参考价值。


将全部的圆化成树,然后就能够转化成树上的删边博弈问题....

Circles Game

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


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
 

Source
php?

field=problem&key=2015+Multi-University+Training+Contest+1&source=1&searchmode=source" style="color:rgb(26,92,200); text-decoration:none">2015 Multi-University Training Contest 1

 



#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:1024000000,1024000000")

const int maxn=20200;

int n;
struct Circle
{
    int x,y,r;
    bool operator<(const Circle& cir) const
    {
        return r>cir.r;
    }
}circle[maxn];

double dist(int a,int b)
{
    return sqrt((circle[a].x-circle[b].x)*(circle[a].x-circle[b].x)
			+(circle[a].y-circle[b].y)*(circle[a].y-circle[b].y));
}

vector<int> edge[maxn];

void Link(int u,int x)
{
    bool fg=true;
	for(int i=0,sz=edge[u].size();i<sz;i++)
    {
        int v=edge[u][i];
        double dd=dist(x,v);
        if(dd+circle[x].r>circle[v].r) continue;
        fg=false;
        Link(v,x);
		return ;
    }
    if(fg) edge[u].push_back(x);
}

int dp[maxn];

void dfs(int u)
{
    int ret=-1;
	for(int i=0,sz=edge[u].size();i<sz;i++)
    {
        int v=edge[u][i];
        dfs(v);
        if(ret==-1) ret=dp[v]+1;
        else ret^=dp[v]+1;
    }
    if(ret==-1) ret=0;
    dp[u]=ret;
}

int main()
{
    int T_T;
    scanf("%d",&T_T);
    while(T_T--)
    {
        scanf("%d",&n);
        for(int i=1,x,y,r;i<=n;i++)
        {
            scanf("%d%d%d",&x,&y,&r);
            //circle[i]=(Circle){x,y,r};
            circle[i].x=x;
            circle[i].y=y;
            circle[i].r=r;
			edge[i].clear();
        }
		edge[0].clear();
        sort(circle+1,circle+1+n);
        for(int i=1;i<=n;i++) 
        {
            Link(0,i); dp[i]=0;
        }
        dfs(0);
        if(dp[0]==0) puts("Bob");
        else puts("Alice");
    }
    return 0;
}



以上是关于HDOJ 5299 Circles Game 圆嵌套+树上SG的主要内容,如果未能解决你的问题,请参考以下文章

hdu5299 Circles Game

计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game

[北京集训测试赛/HDU5299]圆圈游戏(Circles game)-树上删边-圆的扫描线

HDOJ4326 Game

Hdoj 1517.A Multiplication Game 题解

HDOJ1667 The Rotation Game