hdu 3622 Bomb Game (二分+2-sat)

36 篇文章 4 订阅



Bomb Game

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


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


题意:每一对炸弹只能选一个(明显2-sat),每个炸弹半径自定,爆炸范围不可
相交,求那个最小半径的最大值(每种策略的最小半径不同)。

思路: 2-sat一眼题吧, 二分半径, 2-sat判定, 2对炸弹有4种情况, 每种情况如果冲突,那就 i - j`, j - i`,就好了

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 2e3 + 5;
int n, m, low[maxn], dfn[maxn], id[maxn], scc_cnt, dfs_cnt;
int x[maxn], y[maxn];
vector<int> v[maxn];
stack<int> s;
void init()
{
    memset(low, 0, sizeof(low));
    memset(id, 0, sizeof(id));
    memset(dfn, 0, sizeof(dfn));
    scc_cnt = dfs_cnt = 0;
    for(int i = 0; i < maxn; i++)
        v[i].clear();
    while(!s.empty())
        s.pop();
}
void addedge(int x, int y)
{
    v[x].push_back(y);
}
void tarjan(int x)
{
    dfn[x] = low[x] = ++dfs_cnt;
    s.push(x);
    for(int i = 0; i < v[x].size(); i++)
    {
        int to = v[x][i];
        if(!dfn[to])
        {
            tarjan(to);
            low[x] = min(low[x], low[to]);
        }
        else if(!id[to])
            low[x] = min(low[x], dfn[to]);
    }
    if(low[x] == dfn[x])
    {
        scc_cnt++;
        while(1)
        {
            int u = s.top();
            s.pop();
            id[u] = scc_cnt;
            if(x == u) break;
        }
    }
}
void scc()
{
    for(int i = 1; i <= 2*n ; i++)
        if(!dfn[i])
            tarjan(i);
}
double dist(int i, int j)
{
    return (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
}
int check(double r)
{
    init();
    for(int i = 1; i <= 2*n; i+=2)
    {
        for(int j = i+2; j <= 2*n; j+=2)
        {
            if(dist(i, j) < r*r*4)
                addedge(i, j+1), addedge(j, i+1);
            if(dist(i, j+1) < r*r*4)
                addedge(i, j), addedge(j+1, i+1);
            if(dist(i+1, j) < r*r*4)
                addedge(i+1, j+1), addedge(j, i);
            if(dist(i+1, j+1) < r*r*4)
                addedge(i+1, j), addedge(j+1, i);
        }
    }
    scc();
    for(int i = 1; i <= 2*n; i+=2)
        if(id[i] == id[i+1])
            return 0;
    return 1;
}
int main()
{
    while(~scanf("%d", &n))
    {
        for(int i = 1; i <= 2*n; i+=2)
            scanf("%d%d%d%d", &x[i], &y[i], &x[i+1], &y[i+1]);
        double l = 0, r = 1e9, mid;
        int t = 300;
        while(t--)
        {
            mid = (l+r)/2;
            if(check(mid))
                l = mid;
            else
                r = mid;
        }
        printf("%.2f\n", l);
    }
    return 0;
}



Bomb Game

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


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
 

Statistic |  Submit |  Discuss |  Note
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值