HDU 3622 Bomb Game 2-SAT 二分答案
2016-03-25 22:20
441 查看
一个游戏,Robbie每轮有2个格子可以选一个放置相同的炸弹,爆炸半径可控,但前提是炸弹爆炸范围(即圆)不能相交,求最大半径。
似乎转化为判定性问题好做些。
二分爆炸范围。
如果两个格子欧几里得距离小于二倍的半径就不能同时选,连边即可。
Robbie has cracked the game, and he has known all the candidate places of each round before the game starts. Now he wants to know the maximum score he can get with the optimal strategy.
1 1 1 -1
-1 -1 -1 1
2
1 1 -1 -1
1 -1 -1 1
1.00
似乎转化为判定性问题好做些。
二分爆炸范围。
如果两个格子欧几里得距离小于二倍的半径就不能同时选,连边即可。
#include <cstdio> #include <memory.h> #include <cmath> #include <algorithm> using namespace std; #define FOR(i,j,k) for(i=j;i<=k;++i) #define sqr(i) ((i)*(i)) #define ms(i) memset(i,0,sizeof(i)) const int N = 1005, M = 600000; struct Point { double x, y; } pa , pb ; double dis(Point a, Point b) { return sqr(a.x-b.x) + sqr(a.y-b.y); } int h , p[M], v[M], x , y , cnt = 0; int dfn , low , belong , ts = 0, top = 0, scc = 0; int stack , instack ; void add(int a, int b) { p[++cnt] = h[a]; v[cnt] = b; h[a] = cnt; } void tarjan(int x) { int i; dfn[x] = low[x] = ++ts; instack[x] = 1; stack[++top] = x; for (i = h[x]; i; i = p[i]) if (!dfn[v[i]]) { tarjan(v[i]); low[x] = min(low[v[i]], low[x]); } else if (instack[v[i]]) low[x] = min(dfn[v[i]], low[x]); if (dfn[x] == low[x]) { ++scc; do { i = stack[top--]; instack[i] = 0; belong[i] = scc; } while (i != x); } } int main() { int n, m, i, j; while (scanf("%d", &n) == 1) { FOR(i,1,n) scanf("%lf%lf%lf%lf", &pa[i].x,&pa[i].y,&pb[i].x,&pb[i].y); double l=0,r=1e8,mid; while (r - l > 1e-6) { mid = (l + r) / 2; ms(dfn); ms(h); cnt = 0; ts = 0; scc = 0; FOR(i,1,n) FOR(j,i+1,n) { if (dis(pa[i], pa[j]) < mid) add(i, j + n), add(j, i + n); if (dis(pa[i], pb[j]) < mid) add(i, j), add(j + n, i + n); if (dis(pb[i], pa[j]) < mid) add(i + n, j + n), add(j, i); if (dis(pb[i], pb[j]) < mid) add(i + n, j), add(j + n, i); } FOR(i,1,2*n) if (!dfn[i]) tarjan(i); bool flag = true; FOR(i,1,n) if (belong[i] == belong[i + n]) { flag = false; break; } if (flag) l = mid; else r = mid; } printf("%.2lf\n", sqrt(r)/2); } return 0; }
Bomb Game
Problem Description
Robbie is playing an interesting computer game. The game field is an unbounded 2-dimensional region. There are N rounds in the game. At each round, the computer will give Robbie two places, and Robbie should choose one of them to put a bomb. The explosion area of the bomb is a circle whose center is just the chosen place. Robbie can control the power of the bomb, that is, he can control the radius of each circle. A strange requirement is that there should be no common area for any two circles. The final score is the minimum radius of all the N circles.Robbie has cracked the game, and he has known all the candidate places of each round before the game starts. Now he wants to know the maximum score he can get with the optimal strategy.
Input
The first line of each test case is an integer N (2 <= N <= 100), indicating the number of rounds. Then N lines follow. The i-th line contains four integers x1i, y1i, x2i, y2i, indicating that the coordinates of the two candidate places of the i-th round are (x1i, y1i) and (x2i, y2i). All the coordinates are in the range [-10000, 10000].Output
Output one float number for each test case, indicating the best possible score. The result should be rounded to two decimal places.Sample Input
21 1 1 -1
-1 -1 -1 1
2
1 1 -1 -1
1 -1 -1 1
Sample Output
1.411.00
相关文章推荐
- HDU1213 How Many Tables(并查集)
- PHP判断FORM表单或URL参数来的数据是否为整数的方法
- 思科路由器的默认路由
- oracle 的 row_number over 去除重复数据
- 0字节文件删除
- Spring IoC — 基于注解的配置
- CUDA线程配置:
- 在写一个iOS应用之前必须做的7件事
- 求最大公约数
- 计算二叉树中叶子节点的数目
- gnome-packagekit-3.14.3-5.el7.x86_64
- C++精进篇(三)之―常量变量等修饰符
- 好的阅读就是主动阅读
- java 之 helloworld
- Ehcache学习笔记
- idea中使用scala运行spark出现Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class
- C++精进篇(五)之―字符串和字符串函数
- leetcode-SQL(1)
- 哈夫曼编码
- warning: mysql-community-libs-5.7.11-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5