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 ;
}

HDU3622(二分+2-SAT)的更多相关文章

  1. hdu3622 二分+2sat

    题意:      给你N组炸弹,每组2个,让你在这N组里面选取N个放置,要求(1)每组只能也必须选取一个(2)炸弹与炸弹之间的半径相等(3)不能相互炸到对方.求最大的可放置半径. 思路:      二 ...

  2. hdu3622(二分+two-sat)

    传送门:Bomb Game 题意:给n对炸弹可以放置的位置(每个位置为一个二维平面上的点),每次放置炸弹是时只能选择这一对中的其中一个点,每个炸弹爆炸的范围半径都一样,控制爆炸的半径使得所有的爆炸范围 ...

  3. hdu3622 2-sat问题,二分+判断有无解即可。

    /*2-sat问题初破!题意:每一对炸弹只能选一个(明显2-sat),每个炸弹半径自定,爆炸范围不可 相交,求那个最小半径的最大值(每种策略的最小半径不同).思:最优解:必然是选择的点最近 的俩个距离 ...

  4. HDU3622 Bomb Game(二分+2-SAT)

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

  5. 2 - sat 模板(自用)

    2-sat一个变量两种状态符合条件的状态建边找强连通,两两成立1 - n 为第一状态(n + 1) - (n + n) 为第二状态 例题模板 链接一  POJ 3207 Ikki's Story IV ...

  6. 证明与计算(3): 二分决策图(Binary Decision Diagram, BDD)

    0x01 布尔代数(Boolean algebra) 大名鼎鼎鼎的stephen wolfram在2015年的时候写了一篇介绍George Boole的文章:George Boole: A 200-Y ...

  7. Map Labeler POJ - 2296(2 - sat 具体关系建边)

    题意: 给出n个点  让求这n个点所能建成的正方形的最大边长,要求不覆盖,且这n个点在正方形上或下边的中点位置 解析: 当然是二分,但建图就有点还行..比较难想..行吧...我太垃圾... 2 - s ...

  8. LA 3211 飞机调度(2—SAT)

    https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间 ...

  9. UVALive - 3211 (2-SAT + 二分)

    layout: post title: 训练指南 UVALive - 3211 (2-SAT + 二分) author: "luowentaoaa" catalog: true m ...

随机推荐

  1. “全栈2019”Java多线程第三十二章:显式锁Lock等待唤醒机制详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  2. 09_python_初始函数

    一.定义 函数是对功能和动作的封装 def functionname( parameters ): "函数_文档字符串" function_suite return [expres ...

  3. JavaScript对象与JSON字符串的相互转换

    JSON(JavaScript Object Notation) 是JavaScript编程语言的一个子集.正因JSON是JavaScript的一个子集,所以它可清晰的运用于此语言中. eval函数 ...

  4. day 72 crm(9) 客户关系系统,整体实现,以及自定制路由内容,客户关系梳理

    前情提要: crm(9)  ,利用stark 组件和,rbac组键的使用,   明确观点: 一:客户关系需求明确 1:客户关系系统,主要是,本业务逻辑主要是 销售就客户关系的业务逻辑, 二: 创建ap ...

  5. Yarn 资源调度框架

    Yarn 资源调度框架    实现对资源的细粒度封装(cpu,内存,带宽)    此外,还可以通过yarn协调多种不同计算框架(MR,Spark)    概述        Apache Hadoop ...

  6. JAVA实现QRCode的二维码生成以及打印

    喜欢的朋友可以关注下,粉丝也缺. 不说废话了直接上代码 注意使用QRCode是需要zxing的核心jar包,这里给大家提供下载地址 https://download.csdn.net/download ...

  7. Windows上安装tensorflow 详细教程

    原博客转载自:https://www.cnblogs.com/lvsling/p/8672404.html 一, 前言:本次安装tensorflow是基于Python的,安装Python的过程不做说明 ...

  8. python2和3的区别 高清大图:)

    点击图片,新标签中打开查看!或右键‘图片另存为’!

  9. CDH 版本子节点启动问题

    今天下午整整为了启动一个节点瞎忙活一下午,惨痛的教训还是记录下来吧,毕竟付出了代价.事情原委,一个同事在一台机器上占用了大量内存训练CTR点击率模型,而这台机器上部署了分布式Hadoop的一个data ...

  10. web工程迁移---weblogic8迁移到jboss5遇到的异常

    原有的web工程是在weblogic8上运行的,但现在的要求是要运行到jboss5中,为如后迁移到更高版本的jboss做准备 由于我对weblogic没有过研究,所以之前的步骤都是有别人进行的,在进行 ...