hdu 3622 Bomb Game (2-SAT)
来源:互联网 发布:excel中如何引用数据 编辑:程序博客网 时间:2024/06/05 00:16
Bomb Game
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5369 Accepted Submission(s): 1912
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.
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
21 1 1 -1-1 -1 -1 121 1 -1 -11 -1 -1 1
Sample Output
1.411.00
Source
2010 Asia Regional Tianjin Site —— Online Contest
Recommend
lcy | We have carefully selected several similar problems for you: 3625 3628 3629 3627 3621
题解:2-SAT
二分答案,二分最终方案中最近两点的距离(因为这个距离的1/2就是圆的半径)
关键是如何进行check
如果两个点a,b之间的距离小于mid,那么这两个点一定不能同时入选。
也就是选择了a必然要选择b',选择了b必然要选择a'。所以a->b',b->a'
然后用tarjan进行缩点,如果a,a'在同一个强连通分量中则说明mid不可行。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#define N 1003#define eps 1e-4using namespace std;int n,m,top,tot,sz,cnt,belong[N];int point[N],v[N*N],nxt[N*N],num[N][3],dfsn[N],low[N],st[N],ins[N];double a[N][3],b[N][3];void add(int x,int y){tot++; nxt[tot]=point[x]; point[x]=tot; v[tot]=y;//cout<<x<<" "<<y<<endl;}void tarjan(int x){dfsn[x]=low[x]=++sz; st[++top]=x;ins[x]=1;for (int i=point[x];i;i=nxt[i]) {int j=v[i];if (!dfsn[j]) tarjan(j),low[x]=min(low[x],low[j]);else if (ins[j]) low[x]=min(low[x],dfsn[j]);}if (low[x]==dfsn[x]) {int j; ++cnt;do{j=st[top--];belong[j]=cnt;ins[j]=0;}while (j!=x);}}double pow(double x){return x*x;}double getdis(double x,double y,double px,double py){return sqrt(pow(x-px)+pow(y-py));}bool check(double mid){//cout<<mid<<endl;tot=0; sz=0; cnt=0; top=0;memset(point,0,sizeof(point));for (int i=1;i<n;i++) for (int l=0;l<=1;l++) { double x=a[i][l],y=b[i][l]; for (int j=i+1;j<=n;j++) for (int k=0;k<=1;k++){ double px=a[j][k],py=b[j][k]; if (getdis(x,y,px,py)<mid) add(num[i][l],num[j][k^1]),add(num[j][k],num[i][l^1]); } }memset(dfsn,0,sizeof(dfsn));memset(ins,0,sizeof(ins));memset(belong,0,sizeof(belong));for (int i=1;i<=n+n;i++) if (!dfsn[i]) tarjan(i);for (int i=1;i<=n;i++) if (belong[i]==belong[i+n]) return false;return true;}int main(){//freopen("bomb.in","r",stdin);//freopen("bomb.out","w",stdout);while (scanf("%d",&n)!=EOF){for (int i=1;i<=n;i++) scanf("%lf%lf%lf%lf",&a[i][0],&b[i][0],&a[i][1],&b[i][1]);for (int i=1;i<=n;i++) num[i][0]=i,num[i][1]=i+n; double l=0; double r=10000000; double ans=0; while (r-l>=eps) { double mid=(l+r)/2; if (check(mid)) ans=max(ans,mid),l=mid+eps; else r=mid-eps;}printf("%.2lf\n",ans/2.0); }}
0 0
- HDU 3622 Bomb Game(2-SAT)
- hdu 3622 Bomb Game (2-SAT)
- HDU 3622 Bomb Game【2-SAT 问题】
- hdu 3622 Bomb Game#2-sat+二分
- HDU 3622 Bomb Game【2-SAT 问题】
- HDU 3622 Bomb Game 2-sat
- 2-sat->HDU 3622 Bomb Game
- hdu 3622 Bomb Game (二分+2-sat)
- HDU 3622 Bomb Game / 2-SAT
- HDU 3622 Bomb Game(2-SAT+二分)
- 【HDU】3622 Bomb Game 2-sat
- hdu 3622 Bomb Game (2-SAT)
- HDU 3622 Bomb Game(2-sat)
- HDU 3622 Bomb Game (二分+2-SAT)
- HDU 3622 Bomb Game【2-SAT + tarjan】
- HDU 3622 Bomb Game 二分 + 2-sat
- HDU 3622 Bomb Game(2-SAT)
- hdu 3622 Bomb Game(二分+2-sat)
- 小米面试题 :字符串重组
- Apache Spark - Apache HBase Connector
- Filter详解
- java修改文件名
- 用户和组管理常用命令补充
- hdu 3622 Bomb Game (2-SAT)
- 一边搭建一边理解MongoDB副本集(分布于两个或多个数据中心的副本集)
- 多核与异步并行
- PAT甲级1089
- Manachar算法
- 树莓派小旅途
- String与StringBuffer和StringBuilder的区别
- 20个强大的正则表达式
- android入门之布局和控件