hdu3124Arbiter(最小圆距离-扫描线)
详解http://blog.sina.com.cn/s/blog_6e7b12310100qnex.html
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
set<int>st;
struct point
{
double x,y,r;
point(double x = ,double y = ):x(x),y(y){}
int id;
}p[N],rank[N];
struct line
{
double po;
int id;
}lef[N],rig[N];
int rk[N],n,pp[N];
double mid;
typedef point pointt;
point operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y*1.0);
}
int is_cross(int a,int b)
{
double dd = dis(rank[a]-rank[b]);
if(dcmp(dd-rank[a].r-rank[b].r-mid-mid)>) return ;
return ;
}
int judge(int a)
{
set<int>::iterator it=st.insert(a).first;//插入a后所在位置
if(it!=st.begin())
{
if(is_cross(a,*--it))
return ;
it++;
}
if(++it!=st.end())
{
if(is_cross(a,*it)) return ;
}
return ;
}
int cal()
{
st.clear();
int i = ,j = ;
while(i<=n||j<=n)
{
if(j==n+||(i!=n+&&dcmp(lef[i].po-mid-(rig[j].po+mid))<=))//如果当且i圆的最左端小于j圆的最右端 将i插进来
{
int ip = rk[lef[i].id];
if(judge(ip))
return ;
i++;
}
else
{
st.erase(rk[rig[j].id]);
j++;
}
}
return ;
}
double solve()
{
double low = 0.0,high = dis(p[]-p[])-p[].r-p[].r;
while(low+eps<high)//二分距离
{
mid = (high+low)/;
if(cal())
high = mid;
else low = mid;
}
return high+low;
}
bool cmp(line a,line b)
{
return a.po<b.po;
}
bool cmpp(point a,point b)
{
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
}
int main()
{
int t,i;
cin>>t;
while(t--)
{
scanf("%d",&n);
for(i = ; i <=n ;i++)
{
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
lef[i].po = p[i].x-p[i].r;//每个圆的最左端
lef[i].id = i;
rig[i].po = p[i].x+p[i].r;//每个圆的最右端
rig[i].id = i;
rank[i] = p[i];//按y坐标排序
rank[i].id = i;
}
sort(lef+,lef+n+,cmp);
sort(rig+,rig+n+,cmp);
sort(rank+,rank+n+,cmpp);
for(i = ; i <= n; i++)
{
rk[rank[i].id] = i;//每个圆按y坐标排序后位于第几
}
double ans = solve();
printf("%.6f\n",ans);
}
return ;
}
hdu3124Arbiter(最小圆距离-扫描线)的更多相关文章
- @codeforces - 793G@ Oleg and chess
目录 @description - translation@ @solution@ @part - 1@ @part - 2@ @part - 3@ @part - 4@ @accepted code ...
- CSS动效集锦,视觉魔法的碰撞与融合(三)
本文讲述的原理和相关demo 扇形DIV的使用——实现雷达扫描图 DIV环形布局—实现loading圈 动画的向量合成—实现抛物线动画 无限滚动动画—实现跑马灯效果 perspective和trans ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- BZOJ_3476_[Usaco2014 Mar]The Lazy Cow_扫描线+切比雪夫距离
BZOJ_3476_[Usaco2014 Mar]The Lazy Cow_扫描线+切比雪夫距离 Description It's a hot summer day, and Bessie the c ...
- BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...
- BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- 【转换模型+扫描线】【UVA1398】Meteor
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
随机推荐
- northwind数据库介绍
① Categories: 种类表相应字段:CategoryID :类型ID:CategoryName:类型名;Description:类型说明;Picture:产品样本 ② CustomerCust ...
- java面试每日一题10
题目:利用递归方法求5! public class Recursion { public static void main(String args[]) throws NumberFormatExce ...
- 快速排序算法(Java)
快速排序算法的基本思想是:通过一趟排序将待排记录分割成独立的两部分,其中一部分记录的关键字均比另外一部分记录的关键字小,则可分别对这两部分记录继续进行排序,以达到整个序列有序. class Parti ...
- poj3372 Candy Distribution
可以证明: f(k) = k *(k - 1)/ 2 (1 ≤ k ≤ n)是n的完全剩余系当且仅当n = 2 ^ t. http://poj.org/problem?id=3372
- git status message - Your branch is ahead of origin/master by X commits
git reset --hard origin/master git status FAQ: When I issue the "git status" command, I se ...
- acdeream Matrix Multiplication
D - Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- Android图形系统之Surface、SurfaceView、SurfaceHolder及SurfaceHolder.Callback之间的联系
1.Surface Surface extends Objectimplements Parcelable java.lang.Object ↳ android.view.Surface Cla ...
- 微信支付:redirect-uri参数错误 的解决办法
redirect_url参数错误: 报这个错误,说明你的公众号后台授权设置有问题(一般有两处) 一:检查授权目录 答:支付授权目录是网站发起请求的页面所在目录,并且必须是能通过url地址访问的(与真实 ...
- Java开发、网络爬虫、自然语言处理、数据挖掘简介
一.java开发 (1) 应用开发,即Java SE开发,不属于java的优势所在,所以市场占有率很低,前途也不被看好. (2) web开发,即Java Web开发,主要是基于自有或第三方成熟框架的系 ...
- afxmessagebox和messagebox
MessageBox()是Win32API函数.后者是mfc中的全局函数.在MFC中能用MessageBox()的地方都能用AfxMessageBox(). afxmessagebox更多的时候是用于 ...