码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3622 Bomb Game

时间:2014-11-29 17:37:55      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   os   sp   

题意:给n对炸弹可以放置的位置(每个位置为一个二维平面上的点),每次放置炸弹是时只能选择这一对中的其中一个点,每个炸弹爆炸的范围半径都一样,控制爆炸的半径使得所有的爆炸范围都不相交(可以相切),求解这个最大半径。

思路:二分答案,然后建图,用2-SAT判断方案是否可行。


#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
double r;
const double eps=1e-5;
const int MAXN = 110;
struct twosat
{  
    int n,c;  
    vector<int> g[MAXN<<1];  
    bool mark[MAXN<<1];  
    int s[MAXN<<1];  
    
	bool dfs(int x) 
	{  
		int i;
        if (mark[x^1]) 
			return 0;  
        if (mark[x]) 
			return 1;  
        mark[x] = 1;  
        s[c++] = x;  
        for (i = 0; i < g[x].size(); i++)  
            if (!dfs(g[x][i])) 
				return 0;  
        return 1;  
    }  
    
    void init(int n) 
	{  
		int i,t=n<<1;
        this->n = n;  
        for (i = 0; i < t; i++)   
            g[i].clear();  
        memset(mark, 0, sizeof(mark));  
    }  
  
    void add_clause(int x, int xval, int y, int yval) 
	{  
        x = x * 2 + xval;  
        y = y * 2 + yval;  
        g[x^1].push_back(y);  
        g[y^1].push_back(x);  
    }  
  
    bool solve() 
	{  
		int i,t=n<<1;
        for (i = 0; i < t; i += 2)   
            if (!mark[i] && !mark[i + 1]) 
			{  
                c = 0;  
                if (!dfs(i)) 
				{  
                    while (c > 0) 
						mark[s[--c]] =0;   
                    if (!dfs(i + 1)) 
						return 0;  
                }  
            }
        return 1;  
    }  
}woker;  
struct point
{
	double x,y;
	double dis(point a)
	{
		return sqrt(pow(x-a.x,2)+pow(y-a.y,2));
	}
}in[110][2];
bool isok(point a,point b)
{
	return !(a.dis(b)>2*r);
}
void create(int n)
{
	int i,j,x,y;
	woker.init(n);
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			for(x=0;x<2;x++)
				for(y=0;y<2;y++)
					if(isok(in[i][x],in[j][y]))
						woker.add_clause(i,x,j,y);
}
int main()
{
	int i,j,n;
	double low,high;
	while(cin>>n)
	{
		for(i=0;i<n;i++)
			for(j=0;j<2;j++)
				cin>>in[i][j].x>>in[i][j].y;
		low=0;
		high=1e5;
		while(high-low>eps)
		{
			r=(high+low)/2;
			create(n);
			if(woker.solve())
				low=r;
			else
				high=r;
		}
		printf("%.2f\n",low);
	}
	return 0;
}

Bomb Game

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


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
 

hdu 3622 Bomb Game

标签:des   style   blog   http   io   ar   color   os   sp   

原文地址:http://blog.csdn.net/stl112514/article/details/41596631

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!