1. 程式人生 > >HDU 5299 Circles Game

HDU 5299 Circles Game

bob ive memset sea total one dsm bottom 全部

轉化為樹的刪邊遊戲。。。

樹的刪邊遊戲
規則例如以下:
 給出一個有 N 個點的樹,有一個點作為樹的根節點。


 遊戲者輪流從樹中刪去邊,刪去一條邊後,不與根節點相連的
部分將被移走。


 誰無路可走誰輸。
我們有例如以下定理:
[定理]
葉子節點的 SG 值為 0;

中間節點的 SG 值為它的全部子節點的 SG 值加 1 後的異或和。

Circles Game

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


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

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 <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
typedef unsigned long long ll;
const int N = 20003;
struct P
{
	int x, y, r;
	bool operator<(P b) const
	{
		return x < b.x;
	}
	ll d(P b)
	{
		ll dx = x - b.x, dy = y - b.y;
		return dx*dx + dy*dy;
	}
}p[N];
bool vis[N];
bool cmp(P a, P b)
{
	return a.r > b.r;
}
int n;
inline ll sqr(ll x) { return x*x; }
struct Edge
{
	int v, next;
} e[N<<1] ;
int head[N], mm;
void add(int u, int v)
{
//	printf("%d --> %d\n", u, v);
	e[mm].v = v;
	e[mm].next = head[u];
	head[u] = mm++;
}
int dfs(int u)
{
	int ret=  0;
	for (int i=head[u];~i;i=e[i].next) {
		ret ^= dfs(e[i].v)+1;
	}
	return ret;
}
int main()
{
	int re, ca=1; cin>>re;
	while ( re-- )
	{
		memset(head, -1, sizeof head); mm=  0;
		scanf("%d", &n);
		for (int i=0;i<n;i++)
			scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].r);
		sort(p ,p+n, cmp);
		int rt = n;
		for (int i=n-1;i>0;i--) {
			bool ok = false;
			for (int j=i-1;j>=0;j--) { /// r[j] > r[i]
				ll a = p[i].d(p[j]);
				ll b = sqr(p[j].r - p[i].r);
				if (a < b) {
					ok = true;
					add(j, i);
					break;
				}
			}
			if (!ok) {
				add(rt, i);
			}
		}
		add(rt, 0);
		int ans = dfs(rt);
		puts(ans ?

"Alice" : "Bob"); } return 0; }


#include <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
typedef long long ll;
const int N = 20003;
double sqr(double x) { return x*x ; }
struct P
{
    int x, y, r; int id;
    P() {}
    P(int _x, int _y, int _r =0) { x=_x, y=_y, r=_r; }
    void out() { printf("%d : (%d, %d) ---%d\n", id, x,y,r); }
    bool operator < (P b) const
    {
            if (x - b.x) return x < b.x;
            if (y - b.y) return y < b.y;
            return r < b.r;
    }
    double dis(P b) {
                return sqrt(sqr(x-b.x) + sqr(y-b.y) );
        }
}p[N];
double dis(P a, P b) { return a.dis(b); }
bool cmp(P a, P b)
{
        return a.r > b.r;
}
bool vis[N];
struct Edge
{
    int v, next;
} e[N<<1] ;
int head[N], mm;
void add(int u, int v)
{
    e[mm].v = v;
    e[mm].next = head[u];
    head[u] = mm++;
}
int n;
const int Root = N - 1;
int fa[N];
int dfs(int u)
{
    int ret=  0;
    for (int i=head[u];~i;i=e[i].next) {
        ret ^= dfs(e[i].v)+1;
    }
    return ret;
}
set<P>::iterator it;
const int inf = 0x3f3f3f3f;
int main()
{
        int re, ca=1;
        cin>>re;
        while (re--)
        {
                memset(head, -1, sizeof head); mm=  0;
                cin>>n;
                set<P> se;
                for (int i=0;i<n;i++) {
                        scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].r);
                }
                se.insert(P(inf, inf));
                sort(p, p+n, cmp);
                for (int i=0;i<n;i++) p[i].id= i ;
                memset(vis, 0, sizeof vis);
                for (int i=n-1;i>=0;i--) {
                        P l = P(p[i].x - p[i].r, p[i].y - p[i].r);
                        P r = P(p[i].x + p[i].r, p[i].y + p[i].r);
                        set<P>::iterator e,f ;
                        e = se.lower_bound(l);
                        f = se.lower_bound(r);
                        for (set<P>::iterator it = e; it!=se.end() && it!=f; it++)
                        {
                                P tmp = *it;
                                double d = dis(tmp, p[i]);
                                if (!vis[it->id] && d < abs(p[i].r - tmp.r))
                                {
                                        add(i , tmp.id);
                                        vis[tmp.id] = 1;
                                }
                        }
                        se.insert(p[i]);
                }
                for (int i=0;i<n;i++) if (!vis[i]) add(Root, i);
                int ans = dfs(Root);
                puts(ans ? "Alice" : "Bob");
        }
}



HDU 5299 Circles Game