hdu 3622 Bomb Game

题意:给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 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
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值