Bomb Game

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

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
 
Recommend
lcy
 

给出一些点对,你可以在每对中任意选一个,只能选一个,放置一个炸弹,每个炸弹爆炸时都有一个效果范围,会波及到其放置点为圆心,半径为 r 的圆的范围,问如果要让任意两个圆都不相交(可以相切)的话,半径的最大值是多少。

很裸的 2-SAT 模型,每组点分为 A 和 A‘ ,然后2分枚举半径的值,如果两点间距离小于半径的二倍,那么这两点不能同时放置炸弹,也就是说他们矛盾,根据这个关系建边,判断是否存在解,如果存在说明半径还可以继续增大,否则,半径要减小。

PS:这个题的精度问题,输出要求的是10的负二次方,但是精度只开到 1e-3 会wa

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int VM=;
const int EM=;
const double eps=1e-; struct Edge{
int to,nxt;
}edge[EM<<]; int n,m,cnt,dep,top,atype,head[VM];
int dfn[VM],low[VM],vis[VM],belong[VM];
int stack[VM];
double point[VM][]; void Init(){
cnt=, atype=, dep=, top=;
memset(head,-,sizeof(head));
memset(vis,,sizeof(vis));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(belong,,sizeof(belong));
} void addedge(int cu,int cv){
edge[cnt].to=cv; edge[cnt].nxt=head[cu]; head[cu]=cnt++;
} void Tarjan(int u){
dfn[u]=low[u]=++dep;
stack[top++]=u;
vis[u]=;
for(int i=head[u];i!=-;i=edge[i].nxt){
int v=edge[i].to;
if(!dfn[v]){
Tarjan(v);
low[u]=min(low[u],low[v]);
}else if(vis[v])
low[u]=min(low[u],dfn[v]);
}
int j;
if(dfn[u]==low[u]){
atype++;
do{
j=stack[--top];
belong[j]=atype;
vis[j]=;
}while(u!=j);
}
} bool CalDis(int i,int j,double mid){
return (point[i][]-point[j][])*(point[i][]-point[j][])+(point[i][]-point[j][])*(point[i][]-point[j][])-*mid*mid<eps;
} int solve(double mid){
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++){
if(CalDis(i,j,mid)){
addedge(i,j+n);
addedge(j,i+n);
}
if(CalDis(i,j+n,mid)){
addedge(i,j);
addedge(j+n,i+n);
}
if(CalDis(i+n,j,mid)){
addedge(i+n,j+n);
addedge(j,i);
}
if(CalDis(i+n,j+n,mid)){
addedge(i+n,j);
addedge(j+n,i);
}
}
for(int i=;i<=*n;i++)
if(!dfn[i])
Tarjan(i);
for(int i=;i<=n;i++)
if(belong[i]==belong[i+n])
return ;
return ;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n)){
for(int i=;i<=n;i++)
scanf("%lf%lf%lf%lf",&point[i][],&point[i][],&point[i+n][],&point[i+n][]);
double l=,r=,mid,ans=;
while(l+eps<=r){
Init(); //因为二分每次都得重新建边,所以初始化在这里
mid=(l+r)/;
if(solve(mid)){ //return true,说明边太少了,应该增大mid,所以l = mid
l=mid;
ans=mid;
//ans=max(ans,mid);
//printf("ans=%.2lf\n",ans);
}else //return false,说明边太多了,应该减小mid,所以r = mid
r=mid;
}
printf("%.2lf\n",ans);
}
return ;
}

HDU Bomb Game 3622 (2-Sat)的更多相关文章

  1. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5877 Weak Pair(弱点对)

    HDU 5877 Weak Pair(弱点对) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Jav ...

  3. HDU 5813 Elegant Construction(优雅建造)

    HDU 5813 Elegant Construction(优雅建造) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65 ...

  4. HDU 5818 Joint Stacks(联合栈)

    HDU 5818 Joint Stacks(联合栈) Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  5. HDU 2222 Keywords Search(查询关键字)

    HDU 2222 Keywords Search(查询关键字) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...

  6. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  7. HDU 4548 美素数(打表)

    HDU  4548  美素数(打表)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/H 题目 ...

  8. hdu 3709 数字dp(小思)

    http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...

  9. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

随机推荐

  1. EF 数据类型 0xA7 的数据长度或元数据长度无效

    测试方法 TestProject1.SysTest.HtmlAnalysisTest12 引发异常:  System.Data.UpdateException: 更新项时出错.有关详细信息,请参阅“I ...

  2. Spring(八):Spring配置Bean(一)BeanFactory&ApplicationContext概述、依赖注入的方式、注入属性值细节

    在Spring的IOC容器里配置Bean 配置Bean形式:基于xml文件方式.基于注解的方式 在xml文件中通过bean节点配置bean: <?xml version="1.0&qu ...

  3. php获取网址

    #测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br> ...

  4. C++ 构造与析构的执行顺序

    1.代码如下:class A{public: int _Id; A():_Id(0) { printf("A[%d]\n",_Id); } ~A() { printf(" ...

  5. Disqus评论框改造工程-Jekyll等静态博客实现Disqus代理访问

    文章最初发表于szhshp的第三边境研究所转载请注明 关于博客评论 六月多说挂了,地球人都知道. 倡言.云跟帖.来必力都很烂,地球人都知道. 转Disqus的都是人才. Disqus使用中遇到的问题 ...

  6. Discuz常见小问题-如何为每个板块设置不同的图标

    进入后台的论坛-版块管理,选中要修改图标的板块,点击后面的编辑 在板块图标中找到图标文件,一般是PNG或者GIF,大小为32X32,提交之后效果如下

  7. 【自动化测试】基于IntelliJ IDEA的Gradle和testNG

    这几篇文章值得一读: TestNG测试框架使用笔记:http://www.cnblogs.com/xguo/p/3300358.html TestNg官方文档:http://testng.org/do ...

  8. Azure Paas SQL 修改用户名密码的相关问题

    现总结如下,供您参考: 1)  如何单独修改每个数据库的密码? 在portal中,我们提供了一个最高权限的,可管理服务器下所有数据库的服务器用户 跟密码,但在实际使用中,由于权限过大,会有潜在的安全隐 ...

  9. 基于Android的百度地图实现输入地址返回经纬度信息

    1 解决方案一 此处解决办法参照自网友文章,对于输入的地址信息要求:城市名+具体地址名. 如果输入的地址信息只有具体地址名,而没有城市名,可能解析不出经纬度信息.还有就是解析出的经纬度再反向解析显示再 ...

  10. Spring面试题一

    目录一.Spring工作原理 二.为什么要用Spring三.请你谈谈SSH整合四.介绍一下Spring的事务管理五.什么是依赖注入,依赖注入的作用是什么? 六.什么是AOP,AOP的作用是什么? 七. ...