• 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
     
    暴力程序:
    #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
    ", 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
    ", 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");
            }
    }



  • 相关阅读:
    谈谈node(1)
    怎么调用html5的摄像头,录音,视频?
    es6-块级作用域let 和 var的区别
    输入手机号自动分隔
    How do I know which version of Javascript I'm using?
    PHP的类中的常量,静态变量的问题。
    【转】马拉松式学习与技术人员的成长性
    JavaScript Prototype in Plain Language
    Promise编程规范
    XMLHttpRequest对象解读
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/7000690.html
Copyright © 2020-2023  润新知