题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5299

题意:

在欧几里得平面上有n个圆,圆之间不会相交也不会相切,现在Alice和Bob玩游戏,两人轮流选择一个圆删除它和它包含的所有圆(Alice先手),在自己的轮次无圆可删判输,问你谁会赢得比赛

解:先将圆之间的关系抽象,转化为一个树图,然后套SG定理(WoW,我可不知道什么是SG定理

想详细了解的话,这里是和SG函数相关的东西:http://www.cnblogs.com/shjwudp/articles/4715439.html

然后又有SG定理(感觉不想关啊喂:

我们有如下定理:
[定理]
叶子节点的 SG 值为 0; 中间节点的 SG 值为它的所有子节点的 SG 值加 1 后的异或和。

将圆关系抽象这个问题具体就是要查找,每个圆直接包含的圆,看了网上的题解,基本都是O(n^2),(有看起来是O(n logn)的

具体的请看代码理解吧:

 /*
* Problem:
* Author: SHJWUDP
* Created Time: 2015/8/8 星期六 15:06:48
* File Name: 1006.cpp
* State:
* Memo:
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm> using namespace std; const int DIMENSION=; struct Point {
long long x[DIMENSION];
};
struct Circle {
Point o;
int r;
};
struct Edge {
int u, v;
Edge(int u, int v):u(u), v(v) {}
}; int n;
vector<Circle> arr;
vector<Edge> edges;
vector<vector<int> > G;
bool cmp(const Circle & a, const Circle & b) {
return a.r>b.r;
}
void init() {
edges.clear();
G.assign(n+, vector<int>());
}
void addEdge(int u, int v) {
edges.push_back(Edge(u, v));
G[u].push_back(edges.size()-);
}
template<class T> T sqr(T x) { return x * x; }
bool judge(int a, int b) {
if(a==n || b==n) return ;
int d=;
for(int k=; k<DIMENSION; k++) {
d+=sqr(arr[a].o.x[k]-arr[b].o.x[k]);
}
int r=max(arr[a].r, arr[b].r);
return r*r>=d;
}
void fin(int u, int x) {
for(int i : G[u]) {
Edge & e=edges[i];
if(judge(x, e.v)) {
fin(e.v, x);
return;
}
}
addEdge(u, x);
}
int dfs(int u) {
int res=;
for(int i : G[u]) {
Edge & e=edges[i];
res^=+dfs(e.v);
}
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
//freopen("out", "w", stdout);
#endif
int T;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
arr.resize(n);
for(int i=; i<n; i++) {
Circle & c=arr[i];
for(int k=; k<DIMENSION; k++) {
scanf("%I64d", &c.o.x[k]);
}
scanf("%d", &c.r);
}
sort(arr.begin(), arr.end(), cmp); init();
for(int i=; i<n; i++) fin(n, i);
puts(dfs(n)?"Alice":"Bob");
}
return ;
}

hdu5299

[2015hdu多校联赛补题]hdu5299 Circles Game的更多相关文章

  1. [2015hdu多校联赛补题]hdu5384 Danganronpa

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5384 题意:函数f(A, B)定义:A.B为字符串,f(A, B)为A中有多少个不同的B(ex:f(& ...

  2. [2015hdu多校联赛补题]hdu5302 Connect the Graph

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5302 题意:给你一个无向图,它的边要么是黑色要么是白色,且图上的每个点最多与两个黑边两个白边相连.现在 ...

  3. [2015hdu多校联赛补题]hdu5301 Buildings

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题目大意:给你一块由1x1方格组成的矩形区域,其中有且仅有一个坏块,现在你要在上面建矩形的房子, ...

  4. [2015hdu多校联赛补题]hdu5378 Leader in Tree Land

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5378 题意:给你一棵n个结点的有根树.因为是有根树,那么每个结点可以指定以它为根的子树(后面讨论的子树 ...

  5. [2015hdu多校联赛补题]hdu5372 Segment Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5372 题意:进行n次操作,操作分两种,0和1,每一个0操作按出现顺序有一个编号(从1开始 0操作 0 ...

  6. [2015hdu多校联赛补题]hdu5371 Hotaru's problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371 题意:把一个数字串A翻过来(abc翻过来为cba)的操作为-A,我们称A-AA这样的串为N-se ...

  7. [2015hdu多校联赛补题]hdu5303 Delicious Apples

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 题意:在一个长为L的环形路径上种着一些苹果树,告诉你苹果树的位置(题目中以0~L指示坐标)及苹果 ...

  8. [2015hdu多校联赛补题]hdu5348 MZL's endless loop

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5348 题意:给你一个无向图,要你将无向图的边变成有向边,使得得到的图,出度和入度差的绝对值小于等于1, ...

  9. [2015hdu多校联赛补题]hdu5324 Boring Class

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5324 题意:给你一个二维的序列,让你找出最长的第一维升第二维降的子序列(如果多个答案,输出字典序最小) ...

随机推荐

  1. Ioc正解

    IoC是一种模式 IoC(Inversion of Control)中文译为控制反转,目前Java社群中流行的各种轻量级容器的实现都是以IoC模式作为基础的.控制反转意味着在系统开发过程中,设计的类将 ...

  2. LeetCode 【46. Permutations】

    Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have t ...

  3. asp.net ajax 调用一例

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...

  4. Sharepoint CAML 增删改查 List

    Lists.UpdateListItems 方法 (websvcLists) Windows SharePoint Services 3   Adds, deletes, or updates the ...

  5. maven项目修改java编译版本的方式

    背景 使用 maven 3.x 安装到本地后,创建的项目一般都是基于JDK1.5版本.而目前大多数的项目已经升级到1.6或以上,尤其是Servlet3.0 已经要求Java6或以上版本的环境,往往需要 ...

  6. 2W+汉字转拼音JS字库(UTF-8生僻字等通用无乱码)

    测试页面 <html> <head> <script Language="JavaScript" src="pinyin.js"& ...

  7. Hadoop 2.6 MapReduce运行原理详解

    市面上的hadoop权威指南一类的都是老版本的书籍了,索性学习并翻译了下最新版的Hadoop:The Definitive Guide, 4th Edition与大家共同学习. 我们通过提交jar包, ...

  8. How to configure Veritas NetBackup (tm) to write Unified and Legacy log files to a different directory

    Problem DOCUMENTATION: How to configure Veritas NetBackup (tm) to write Unified and Legacy log files ...

  9. impala简单使用

    impala-shell connect ha1:21000 更新元信息 invalidate metadata;

  10. img会在特定的情况下主动的第二次调用MVC的action

    当img的src为空,或者不是合法路径的时候,会连续调用MVC的action两次,第二次所传的值为src的值,这常常会导致程序报错. 这不是MVC的issue,而是浏览器的行为,当response f ...