Bomb Game

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

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

 
题意:每次给出两个点,选其中一点为圆心画圆,半径任意。n次以后,画了n个圆,要求任意两个圆不能相交,问最小圆的半径最大为多少。
思路:二分最小圆的半径。
     check方法:若a点和b点的距离小于2×半径,NOT a和b连边,NOT b和a连边。
         建图完毕后,强连通分量分解,2-SAT判断是否可行。
 //2017-08-27
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath> using namespace std; const int N = ;
const int M = N*N;
const double EPS = 1e-;
int head[N], rhead[N], tot, rtot;
struct Edge{
int to, next;
}edge[M], redge[M]; void init(){
tot = ;
rtot = ;
memset(head, -, sizeof(head));
memset(rhead, -, sizeof(rhead));
} void add_edge(int u, int v){
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++; redge[rtot].to = u;
redge[rtot].next = rhead[v];
rhead[v] = rtot++;
} vector<int> vs;//后序遍历顺序的顶点列表
bool vis[N];
int cmp[N];//所属强连通分量的拓扑序 //input: u 顶点
//output: vs 后序遍历顺序的顶点列表
void dfs(int u){
vis[u] = true;
for(int i = head[u]; i != -; i = edge[i].next){
int v = edge[i].to;
if(!vis[v])
dfs(v);
}
vs.push_back(u);
} //input: u 顶点编号; k 拓扑序号
//output: cmp[] 强连通分量拓扑序
void rdfs(int u, int k){
vis[u] = true;
cmp[u] = k;
for(int i = rhead[u]; i != -; i = redge[i].next){
int v = redge[i].to;
if(!vis[v])
rdfs(v, k);
}
} //Strongly Connected Component 强连通分量
//input: n 顶点个数
//output: k 强连通分量数;
int scc(int n){
memset(vis, , sizeof(vis));
vs.clear();
for(int u = ; u < n; u++)
if(!vis[u])
dfs(u);
int k = ;
memset(vis, , sizeof(vis));
for(int i = vs.size()-; i >= ; i--)
if(!vis[vs[i]])
rdfs(vs[i], k++);
return k;
} int n;
struct Point{
int x, y;
}point[N]; //input: 两个点
//output: 两点间距离
double distance(Point a, Point b){
return sqrt((double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} //input:radius 半径
//output:true 通过选取某些点可以得到radius的分数,false 无法得到radius的分数
bool check(double radius){
init();
for(int i = ; i < *n; i++){
for(int j = i+; j < *n; j++){
if((i^) == j)continue;
if(distance(point[i], point[j]) < *radius){//i与j存在矛盾
add_edge(i^, j);// NOT i -> j
add_edge(j^, i);// NOT j -> i
}
}
}
scc(*n);
for(int i = ; i < *n; i += ){
if(cmp[i] == cmp[i^])
return false;
}
return true;
} int main()
{
std::ios::sync_with_stdio(false);
//freopen("inputC.txt", "r", stdin);
while(cin>>n){
for(int i = ; i < n; i++){
cin>>point[*i].x>>point[*i].y>>point[*i+].x>>point[*i+].y;
}
double l = 0.0, r = 40000.0, mid, ans = ;
while(r-l > EPS){
mid = (l+r)/;
if(check(mid)){
ans = mid;
l = mid;
}else
r = mid;
}
cout.setf(ios::fixed);
cout<<setprecision()<<ans<<endl;
} return ;
}

随机推荐

  1. 关于v$datafile中system表空间的status值始终为system

    http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_1076.htm#REFRN30050 http://blog.itpub ...

  2. Leetcode-462 Minimum Moves to Equal Array Elements II

    #462.   Minimum Moves to Equal Array Elements II Given a non-empty integer array, find the minimum n ...

  3. 读书笔记——Windows核心编程(8)Interlocked系列函数

    先让我们来复习下小学知识 A+B=C//式中A为被加数,B为加数. A-B=C//式中A为被减数,B为减数. 再让我们来明确一个知识点:返回值为void的Windows函数意味着一定会执行成功. -- ...

  4. 图片的copy,从一个目录复制到另一个目录

    代码: public function index(){ $path='G:/相片/2014.9.8深圳莲花山/IMG_1282.JPG'; $path=iconv('utf-8','gb2312', ...

  5. Nagios 安装及微信短信提醒

    引言 Nagios 作为业界非常强大的一款开源监视系统. 监控网络服务(SMTP.POP3.HTTP.NNTP.PING 等): 监控主机资源(处理器负荷.磁盘利用率等): 简单地插件设计使得用户可以 ...

  6. 计算内存容量(measure)

    $m =gwmi Win32_PhysicalMemory $m|measure -Property capacity #计算 Property 出现次数 $m|measure -Property c ...

  7. Expand the scale swarm 副本增减实现负载均衡

    #创建好了swarm集群后,我们可以部署一个httpd应用来了解工作情况:#执行以下命令来部署应用: docker service create --name web_server httpd --n ...

  8. c# c/s 框架的分页用户控件,还有事件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...

  9. Jquery 组 标签页

    <!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...

  10. 【python--函数解读】

    1.strip()函数:用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列(包括'\n', '\r',  '\t',  ' ') 注意: 该方法只能删除开头或是结尾的字符,不能删除中间部分的 ...