[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.
[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
原创粉丝点击