HDU 5299 Circles Game

转化为树的删边游戏。。。

树的删边游戏

规则例如以下:

 给出一个有 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");
        }
}
时间: 2024-11-08 18:16:47

HDU 5299 Circles Game的相关文章

hdu 5299 Circles Game(博弈)

题目链接:hdu 5299 Circles Game 每个分离的圆都是单独的游戏,Nim值为该圆嵌套中的圆的Nim和,最后加1. #include <cstdio> #include <cstring> #include <vector> #include <set> #include <algorithm> using namespace std; const int maxn = 20005; typedef long long ll; st

【SG博弈】HDU 5299 Circles Game

通道:http://acm.hdu.edu.cn/showproblem.php?pid=5299 题意:n个不相交相切的圆,每次操作删圆及其内部的圆,不能删者败. 思路:建边,然后树上SG即可. 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <set> 4 #include <algorithm> 5 6 using namespace std; 7 8 const int MAX_N =

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

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 go

[多校2015.01.1012 博弈] hdu 5299 Circles Game

题意: 在无限大的平面内给你n个圆,两个圆之间只可能是包含或者相离 A和B每次选择一个圆,删除这个圆连通它所包含的所有圆 谁不能选择圆删除了,谁就输了 思路: 所有圆可以构造成一棵树,然后按树上SG博弈来做就好了. 树的删边游戏 规则如下: 给出一个有 N 个点的树,有一个点作为树的根节点. 游戏者轮流从树中删去边,删去一条边后,不与根节点相连的部分将被移走. 谁无路可走谁输. 我们有如下定理: [定理] 叶子节点的 SG 值为 0; 中间节点的 SG 值为它的所有子节点的 SG 值加 1 后的

hdu 5299(树上删边游戏) Circles Game

题意: 给你一些圆圈的圆心坐标和半径,保证这些圆圈是包含或者相离的.现在两个人做博弈操作,拿掉一个圆圈,然后这个圆圈所包含的都要移除掉.两个人一直拿下去,直到某个人找不到一个可以移除的圈他就输了. 思路 学习的姿势.这是一个树上删边游戏模型: 首先按照半径升序排序,然后对于每一个圆找第一个包含它的圆,然后连一条边.建树完成. 叶子节点的SG值为0; 中间节点的 SG 值为它的所有子节点的 SG 值加 1 后的异或和; 这里可以建立成森林或者直接一棵树,没有太大区别.建成一棵树估计要方便一些吧.

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 tabl

hdu 5299 ZCC loves strings

结论:对于串a和b,游戏中先手必胜当且仅当|a|+|b|为奇数或a=b. 我们按|a|+|b|的大小从小到大考虑所有的情况. 当|a|+|b|=0时,显然先手必败,符合结论. 假设已经证明了|a|+|b|=k的所有情况满足结论,现在考虑|a|+|b|=p的情况. 若p是奇数,先手只需要选择长度较短的不为空的串,并使用A操作,就可以转移到|a|+|b|为偶数并且两个串不相等或者两个串均为空的情况,这种情况先手必败,故此时先手必胜. 若p是偶数,如果两个串相等,显然先手只需要选择使用B操作就能获得胜

2015 ACM多校训练第一场

在下面网址看效果更佳>_< http://mlz000.github.io/2015/08/07/2015-ACM%E5%A4%9A%E6%A0%A1%E8%AE%AD%E7%BB%83%E7%AC%AC%E4%B8%80%E5%9C%BA/ 题外话 这个暑假以前就决定要把这次多校的所有题全补了,中间断断续续,总算把第一场的题补全了,鄙视一下颓废的自己... hdu 5288(1001) OO's Sequence Solution 水题,定义两个数组L[i],R[i]示第i个数左侧和右侧最接

HDU 3622 Bomb Game(二分+2-SAT)

Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5396    Accepted Submission(s): 1925 Problem Description Robbie is playing an interesting computer game. The game field is an unbounde