Bomb Game
hdu3622:http://acm.hdu.edu.cn/showproblem.php?pid=3622
题意:你有n次,每次你可以在平面上放置一个点,并且每一次都会有两个位置可以选,每一次只能选择其中一个。然后在自己位置上以该点为圆心画圆,这n个圆不能相交,问你最后最小的圆的半径的最大值是多少。
题解:二分+2-sat。对于2-sat的建图始终很迷糊。这里的一次有两个点,并且每一次能选择其中一个,这就相当于把n个点弄成了2*n点。如果i--j距离太近 ,则建边i-->~j,j—>~i.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
const int N=;
const int M=;
const double eps=1e-;
struct Edge{
int to,next;
} edge[M];
struct Node{
double x;
double y;
}num1[];
int n,m,cnt,dep,top,atype;
int dfn[N],low[N],vis[N],head[N],st[N],belong[N],in[N],out[N],sum[N];
//sum[i]记录第i个连通图的点的个数,in[i],out[i],表示缩点之后点的入度和初度。
void init(){
cnt=dep=top=atype=;
memset(head,-,sizeof(head));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(vis,,sizeof(vis));
memset(belong,,sizeof(belong));
memset(in,,sizeof(in));
memset(out,,sizeof(out));
memset(sum,,sizeof(sum));
}
void addedge(int u,int v){
edge[cnt].to=v;
edge[cnt].next=head[u];
head[u]=cnt++;
} void Tarjan(int u){
dfn[u]=low[u]=++dep;
st[top++]=u;
vis[u]=;
for(int i=head[u]; i!=-; i=edge[i].next){
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=st[--top];
belong[j]=atype;
sum[atype]++; //记录每个连通分量中点的个数
vis[j]=;
}
while(u!=j);
}
}
bool judge(double mid){
init();
//int base=2*n;
for(int i=;i<=*n;i++){
for(int j=i+;j<=*n;j++){
double dis=sqrt((num1[i].x-num1[j].x)*(num1[i].x-num1[j].x)+(num1[i].y-num1[j].y)*(num1[i].y-num1[j].y));
if(dis<*mid){
if(i<=n&&j<=n){
addedge(i,j+n);
addedge(j,i+n);
}
if(i<=n&&j>n){
addedge(i,j-n);
addedge(j,i+n);
}
if(i>n&&j<=n){
addedge(i,j+n);
addedge(j,i-n);
}
if(i>n&&j>n){
addedge(i,j-n);
addedge(j,i-n);
} }
}
}
for(int i=;i<=*n;i++)
if(!dfn[i])Tarjan(i);
for(int i=;i<=n;i++)
if(belong[i]==belong[i+n])
return false; return true; }
int main(){
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%lf %lf %lf %lf",&num1[i].x,&num1[i].y,&num1[i+n].x,&num1[i+n].y);
}
double l=,r=,ans=;
while(abs(l-r)>eps){
double mid=(l+r)/2.0;
if(judge(mid)){
ans=mid;
l=mid;
}
else{
r=mid;
}
}
printf("%.2f\n",ans);
} }
Bomb Game的更多相关文章
- HDU3555 Bomb[数位DP]
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- Leetcode: Bomb Enemy
Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return ...
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Bomb
Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro ...
- CF 363B One Bomb(枚举)
题目链接: 传送门 One Bomb time limit per test:1 second memory limit per test:256 megabytes Description ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- [HDU3555]Bomb
[HDU3555]Bomb 试题描述 The counter-terrorists found a time bomb in the dust. But this time the terrorist ...
- hdu 5934 Bomb
Bomb Problem Description There are N bombs needing exploding.Each bomb has three attributes: explodi ...
- HDOJ 3555 Bomb
数位DP的DFS写法.... Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Oth ...
随机推荐
- mybatis06 增删改差 源码
user.java package cn.itcast.mybatis.po; import java.util.Date; public class User { private int id; p ...
- 关于cocos2d-x精灵加亮及变灰效果
//根据现有CCSprite,变亮和变灰 static CCSprite* graylightWithCCSprite(CCSprite* oldSprite,bool isLight) { //CC ...
- VC++文件相关操作的函数封装实现
在开发编译工具中,需要用到文件的相关操作,于是就封装了相关的函数实现: //判断文件是否存在 BOOL FileIsExist(CString strFileName) { CFileFind fin ...
- python基础知识十
特殊的方法 在类中有一些特殊的方法具有特殊的意义,比如__init__和__del__方法,它们的重要性我们已经学习过了. 一般说来,特殊的方法都被用来模仿某个行为.例如,如果你想要为你的类使用x[k ...
- asp IIS部署An error occurred on the server when processing the URL错误提示解决
An error occurred on the server when processing the URL. Please contact the system administrator.If ...
- MyBatis的学习总结六:Mybatis的缓存【参考】
一.Mybatis缓存介绍 正如大多数持久层框架一样,Mybatis同样提供了一级缓存和二级缓存 1.一级缓存:基于PerpetualCache的HashMap本地缓存,其存储作用域为Session, ...
- 关于jQuery $.isNumeric vs. $.isNaN vs. isNaN
在jQuery中,有几种方式可以判断一个对象是否是数字,或者可否转换为数字. 首先,jQuery.isNaN()在最新版本中已经被移除了(1.7之后),取而代之的是 jQuery.isNumeric ...
- iOS崩溃报告获取一
在AppDelegate.m文件中实现函数 void UncaughtExceptionHandler(NSException *exception) { /** * 获取异常崩溃信息 */ NSAr ...
- gulp + browserSync 一起提高前端开发效率吧!
前端开发的时候,每次修改代码后,要移动鼠标到浏览器选中再刷新查看效果,不知觉间我们的加班的时间又增加了0.5s, 真是罪孽!所以在使用gulp之后,就一直对能自动监听文件刷新页面的browserSyn ...
- 逻辑回归:使用SGD(Stochastic Gradient Descent)进行大规模机器学习
Mahout学习算法训练模型 mahout提供了许多分类算法,但许多被设计来处理非常大的数据集,因此可能会有点麻烦.另一方面,有些很容易上手,因为,虽然依然可扩展性,它们具有低开销小的数据集.这样一个 ...