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 ...
随机推荐
- DTrace Probes in HotSpot VM----java
http://docs.oracle.com/javase/6/docs/technotes/guides/vm/dtrace.html http://docs.oracle.com/javase/7 ...
- MySQL源码:索引相关的数据结构
http://www.orczhou.com/index.php/2012/11/mysql-source-code-data-structure-about-index/ 本文将尝试介绍MySQL索 ...
- raft 分布式协议 -- mongodb
http://www.mongoing.com/presentations/webinar-raft-consensus-in-mongodb#rd
- PureMVC(JS版)源码解析(七):Mediator类
之前的博文中,我们分析了SimpleCommand类和MacroCommand类,这两个类用作"业务逻辑(business logic)"处理,今天,我们讲一些和UI界面相关联的M ...
- CSS背景颜色、背景图片、平铺、定位、固定
CSS背景颜色设置 background-color:red;如设置背景颜色为红色: 背景颜色设置支持3种写法: 颜色名 16进制 rgb CSS背景图片颜色设置 background-image:u ...
- LAMP网站架构方案分析
本文引自:http://www.williamlong.info/archives/1908.html LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框 ...
- 会话技术之Cookie 和 Session
为什么要使用会话技术 会话从字面上来说就是,就是两个人说话,也就是两个人交流,那么这里说的是计算机web端的交流,因为互联网是基于HTTP传输信息的,而http传输是无状态协议,缺少状态,意味着如果后 ...
- [Excel] CsvHelper---C#关于CSV文件的导入和导出以及转化 (转载)
点击下载 CsvHelper.rar 这个类是关于Csv文件的一些高级操作1.DataTable导出到CSV2.将Csv读入DataTable看下面代码吧 /// <summary> // ...
- google map getLocation参考
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- jsp - 引用 jar包.
在jsp中使用不同的方式引用jar,准备的工作也不同.我接触过的有两种:1)直接在jsp页面中引用;2)在src下的java类中引用,然后在jsp中调用java类. 1)直接引用:可以将jar包丢到W ...