[HDU3622][2-sat]Bomb Game
来源:互联网 发布:Ubuntu安装时跨硬盘 编辑:程序博客网 时间:2024/05/29 19:07
[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.
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.
[Algorithm]
2-sat
[Analysis]
枚举r,对每一个r建图,如果在当前r下两个圆有交集就算做2-sat中的不能同时出现的两个元素,跑一下2-sat看看能不能成立。
[Pay Attention]
这种感觉是经典模型但却在细节上无法确定两个元素具体关系的问题,就要靠二分来解决
[Code]
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <iostream>using namespace std;#define MAXN 210#define MAXM 40010#define EPS 1e-4struct point { double x, y;};struct graph{ int point[MAXN], next[MAXM], v[MAXM]; int tot; graph() { memset(point, 0, sizeof(point)); memset(next, 0, sizeof(next)); memset(v, 0, sizeof(v)); tot = 0; } void clear() { memset(point, 0, sizeof(point)); memset(next, 0, sizeof(next)); memset(v, 0, sizeof(v)); tot = 0; } void insert(int x, int y) { tot++; next[tot] = point[x]; point[x] = tot; v[tot] = y; }}; inline double dis(point a, point b){ return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}inline int group(int x){ return (x + 1) / 2;}inline int part(int x){ return ((x - 1) ^ 1) + 1;}graph ori;point a[MAXN];int dfsTime[MAXN], lessTime[MAXN], cct[MAXN], st[MAXN], top, cntCct;int nowTime;int n;void tarjan(int now){ nowTime++; dfsTime[now] = lessTime[now] = nowTime; st[++top] = now; for (int temp = ori.point[now]; temp; temp = ori.next[temp]) { int tar = ori.v[temp]; if (!dfsTime[tar]) { tarjan(tar); lessTime[now] = min(lessTime[now], lessTime[tar]); } else if (!cct[tar]) lessTime[now] = min(lessTime[now], dfsTime[tar]); } if (dfsTime[now] == lessTime[now]) { cntCct++; while (1) { cct[st[top]] = cntCct; top--; if (st[top + 1] == now) break; } }}bool major(double r){ memset(dfsTime, 0, sizeof(dfsTime)); memset(lessTime, 0, sizeof(lessTime)); memset(cct, 0, sizeof(cct)); memset(st, 0, sizeof(st)); top = 0; cntCct = 0; nowTime = 0; ori.clear(); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (i != j && group(i) != group(j) && dis(a[i], a[j]) < r * 2) { ori.insert(i, part(j)); ori.insert(j, part(i)); } for (int i = 1; i <= n; i++) if (!dfsTime[i]) tarjan(i); for (int i = 1; i <= n / 2; i++) if (cct[i * 2 - 1] == cct[i * 2]) return false; return true;}int main(){ //freopen("input.txt", "r", stdin); while (scanf("%d", &n) != EOF) { n *= 2; for (int i = 1; i <= n; i++) scanf("%lf%lf", &a[i].x, &a[i].y); double left = 0, right = 40000; while (right - left >= EPS) { double mid = (left + right) / 2; if (major(mid)) left = mid; else right = mid; } printf("%.2f\n", left); }}
0 0
- [HDU3622][2-sat]Bomb Game
- hdu3622 Bomb Game(二分+2-SAT)
- HDU3622-Bomb Game(2-SAT+二分)
- hdu3622 Bomb Game--2-sat & 二分
- [HDU3622]Bomb Game(2-SAT)
- [二分 + 2-SAT] HDU3622: Bomb Game
- 【HDU3622】Bomb Game-二分答案+2-SAT
- hdu3622 Bomb Game(2分答案+2sat判定)
- HDU3622 Bomb Game(2-SAT 问题,The 35th ACM/ICPC Asia Regional Tianjin ,Online)
- HDU3622.Bomb Game——2-sat二分最大值+可行性判定
- HDU3622 Bomb Game
- HDU3622 Bomb Game
- 3622 Bomb Game //2--SAT
- HDU3622 二分+2-SAT
- HDU3622(二分+2-SAT)
- hdu3622 二分+2sat
- hdu3622 2-SAT+二分
- HDU 3622 Bomb Game【2-SAT 问题】
- Python入门教程-07 列表list
- Android之GridView初步认识
- 游戏资源提取软件介绍
- 点积与叉积
- Java参数传递
- [HDU3622][2-sat]Bomb Game
- CentOS下安装vsftpd
- Buffer类的详解
- C/C++中static机制的一点研究
- OSGi版本的HelloWorld实践
- HDU 4228 Flooring Tiles (反素数应用)
- 好的他非要他呼吁i换肤vfg
- ACM-计算几何之Wall——poj1113
- 《深入理解Java虚拟机》读书笔记---第一章 走进Java