hdu 3622 (twosat)

Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3090    Accepted Submission(s): 1044


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 x 1i, y 1i, x 2i, y 2i, indicating that the coordinates of the two candidate places of the i-th round are (x 1i, y 1i) and (x 2i, y 2i). 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
  
  
2 1 1 1 -1 -1 -1 -1 1 2 1 1 -1 -1 1 -1 -1 1
 

Sample Output
  
  
1.41 1.00
 

Source
 

Recommend
lcy
 
每对炸弹必须选一个引爆,引爆构成一个圆,使所有的圆不相交,求圆的最大半径。最小值最大,二分。每对必须选一个,那么把其中一个看成真,另一个为假,然后任意两个点的距离小于2倍的爆炸半径就是有矛盾的,连边i->j' j->i',然后跑一遍twosat判断当前半径是否可行。
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn = 100 + 5;
const int INF = 100000 + 5;

struct TwoSAT {
  int n;
  vector<int> G[maxn*2];
  bool mark[maxn*2];
  int S[maxn*2], c;

  bool dfs(int x) {
    if (mark[x^1]) return false;
    if (mark[x]) return true;
    mark[x] = true;
    S[c++] = x;
    for (int i = 0; i < G[x].size(); i++)
      if (!dfs(G[x][i])) return false;
    return true;
  }

  void init(int n) {
    this->n = n;
    for (int i = 0; i < n*2; i++) G[i].clear();
    memset(mark, 0, sizeof(mark));
  }
  
  bool solve() {
    for(int i = 0; i < n*2; i += 2){
      if(!mark[i] && !mark[i+1]) {
        c = 0;
        if(!dfs(i)) {
          while(c > 0) mark[S[--c]] = false;
          if(!dfs(i+1)) return false;
        }
      }
    }
    return true;
  }
};

TwoSAT solver;

int a1[maxn],b1[maxn],a2[maxn],b2[maxn];
double dis(int x1,int y1,int x2,int y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        for(int i = 0;i < n;i++){
            scanf("%d%d%d%d",&a1[i],&b1[i],&a2[i],&b2[i]);
        }
        double l = 0,r = INF*1.0,mid,ans;
        for(int t = 0;t < 100;t++){
            mid = (l+r) / 2;
            solver.init(n);
            for(int i = 0;i < n;i++){
                for(int j = i+1;j < n;j++){
                    double dis1 = dis(a1[i],b1[i],a1[j],b1[j]);
                    double dis2 = dis(a1[i],b1[i],a2[j],b2[j]);
                    double dis3 = dis(a2[i],b2[i],a1[j],b1[j]);
                    double dis4 = dis(a2[i],b2[i],a2[j],b2[j]);
                    if(dis1 < 2*mid){
                        solver.G[2*i].push_back(2*j+1);
                        solver.G[2*j].push_back(2*i+1);
                    }
                    if(dis2 < 2*mid){
                        solver.G[2*i].push_back(2*j);
                        solver.G[2*j+1].push_back(2*i+1);
                    }
                    if(dis3 < 2*mid){
                        solver.G[2*i+1].push_back(2*j+1);
                        solver.G[2*j].push_back(2*i);
                    }
                    if(dis4 < 2*mid){
                        solver.G[2*i+1].push_back(2*j);
                        solver.G[2*j+1].push_back(2*i);
                    }
                }
            }
            if(solver.solve()){
                ans = mid;
                l = mid;
            }
            else r = mid;
        }
        printf("%.2lf\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值