zoukankan      html  css  js  c++  java
  • HDU 3622 Bomb Game(2-sat)

    Bomb Game

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


    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
    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
     
     
    距离最少值尽量大,,典型的二分 , 加上每个bomb有2种放法(只能取任意一种), 就是一个2-sat.
     
     注意一下精度,这里会卡一下。1e-4 可以过了
     
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <stack>
    #include <map>
    #include <cmath>
    
    using namespace std;
    
    #define eps 1e-5
    const int N = 210;
    const int M = 400010;
    
    int n , m ;
    
    int st[N] , top ;
    bool mark[N];
    int eh[N] , et[M] , nxt[M] , tot ;
    struct node { double x , y ; }e[N];
    
    
    void init()
    {
        tot = 0 ;
        memset( eh , -1 , sizeof eh );
        memset( mark , false , sizeof mark );
    }
    
    void addedge( int u , int v ){
        et[tot] = v , nxt[tot] = eh[u] , eh[u] = tot ++ ;
        et[tot] = u , nxt[tot] = eh[v] , eh[v] = tot ++ ;
    }
    
    bool dfs( int u )
    {
        if( mark[u] ) return true;
        if( mark[u^1] ) return false;
        mark[u] = true ;
        st[top++] = u ;
        for( int i = eh[u] ; ~i ; i = nxt[i] ){
            int v = et[i];
            if( !dfs(v^1) ) return false;
        }
        return true;
    }
    
    bool solve()
    {
        for(int i = 0 ; i < 2 * n ; i += 2 ){
            if( !mark[i] && !mark[i+1] ){
                top = 0 ;
                if( !dfs(i) ){
                    while( top > 0 ) mark[ st[--top] ] = false;
                    if( !dfs(i+1) ) return false ;
                }
            }
        }
        return true;
    }
    
    inline double dis( int i , int j )
    {
        return sqrt( ( e[i].x - e[j].x ) * ( e[i].x - e[j].x ) + ( e[i].y - e[j].y ) * ( e[i].y - e[j].y ) ) ;
    }
    
    bool test( double DIS )
    {
        init();
        for( int i = 0 ; i < 2 * n ; i += 2 ){
            for( int j = i + 2 ; j < 2 * n ; j += 2 ){
                if( dis( i , j ) < DIS )addedge( i , j );
                if( dis( i , j^1 ) < DIS )addedge( i , j^1 );
                if( dis( i^1 , j ) < DIS )addedge( i^1 , j ) ;
                if( dis( i^1 , j^1 ) < DIS )addedge( i^1 , j^1 );
            }
        }
        return solve();
    }
    
    
    int main()
    {
        #ifdef LOCAL
            freopen("in.txt","r",stdin);
        #endif // LOCAL
        ios::sync_with_stdio(0);
    
        while( ~scanf("%d",&n) ){
            for( int i = 0 ; i < 2 * n ; ++i ){
                scanf("%lf%lf",&e[i].x,&e[i].y);
            }
    
            double l = 0.0 , r = sqrt( pow(20000.0,2.0) + pow(20000.0,2.0) );
            while( l + eps <= r ){
                double m = ( l + r ) / 2.0 ;
                
                if( test(m) )
                    l = m  ;
                else
                    r = m - eps ;
            }
            printf("%.2lf
    ",l/2);
        }
    }
    View Code
    only strive for your goal , can you make your dream come true ?
  • 相关阅读:
    Element-UI饿了么时间组件控件按月份周日期,开始时间结束时间范围限制参数
    揭秘(爱奇艺、优酷、腾讯)在线视频网站视频2倍速、多倍速快速播放的前端实现方法
    提高敲代码的效率:程序员同扭曲时间的事儿抗争
    原生JS在网页上复制的所有文字后面自动加上一段版权声明
    .net core kafka 入门实例 一篇看懂
    聊聊Grpc使用中的坑以及怎么填
    MongoDB 上手开发实践(入门上手就这一篇)
    聊聊redis实际运用及骚操作
    .NET Core 微服务之Polly熔断策略
    .NET Core 微服务之Polly重试策略
  • 原文地址:https://www.cnblogs.com/hlmark/p/4019566.html
Copyright © 2011-2022 走看看