题目链接: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

最新文章

  1. ATM模拟器(附代码及运行结果)
  2. dp跟px的互相转换
  3. HSDB
  4. 开机取消显示 系统准备工具(Sysprep)
  5. Android 反编译工具简介
  6. C语言中fseek函数
  7. Android 内存相关 onTrimMemory,onLowMemory,MemoryInfo()
  8. WPF Delegate委托整理
  9. SQL Server中的Merge关键字 更新表数据
  10. 以守护进程的方式部署flask
  11. 第三节 pandas续集
  12. jmeter 入门学习-通过代理录制测试脚本
  13. Android RecycleView多种布局实现(工厂模式)
  14. Goland could not launch process: decoding dwarf section info at offset 0x0: too short 解决方案
  15. 在Linux上安装Elasticsearch Head工具.md
  16. Java并发编程系列之三十二:丢失的信号
  17. Ubuntu中更改所有子文件和子目录所有者权限
  18. linux下的各个目录(待填)
  19. 二分检索函数lower_bound()和upper_bound()
  20. wavepicking

热门文章

  1. 快速理解Java中的五种单例模式
  2. [poj 1502]昂贵的聘礼
  3. 在Linux系统中如何设置APACHE服务器里的后台页面只允许某个IP地址访问
  4. Python-select详解(select、epoll)
  5. 单例设计模式getInstance()
  6. linux库列表
  7. Sql日期时间格式转换(转)
  8. android中的AIDL进程间通信
  9. jQuery中的事件机制深入浅出
  10. 无法作为数据库主体执行,因为主体 &quot;dbo&quot; 不存在、无法模拟这种类型的主体,或您没有所需的权限。 已将数据库上下文更改为