UVALive 4818 - Largest Empty Circle on a Segment (计算几何)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2819
题目意思:
给了平面上的n条线段:
让你在x轴上[0,L]的范围内找一个点作为圆心,画一个圆,这个圆不能把线段包含在里面去。
求最大的半径。
求解:
二分最终的答案,求解。
对于二分的半径值,对每条线段找出对于x位置上满足半径要求的段。
看n条线段有没有交集就可以了。
/* ***********************************************
Author :kuangbin
Created Time :2014/5/10 23:18:09
File Name :E:\2014ACM\区域赛练习\2010\2010SouthEastern_European_Region\C.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const double eps = 1e-;
const double inf = 1e5;
const double pi = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps)return ;
else if(x < )return -;
return ;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
double len()
{
return hypot(x,y);
}
double distance(Point p)
{
return hypot(x-p.x,y-p.y);
}
};
struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;
e = _e;
}
void input()
{
s.input();
e.input();
}
double length()
{
return s.distance(e);
}
double dispointtoline(Point p)
{
return fabs((p-s)^(e-s))/length();
}
double dispointtoseg(Point p)
{
if(sgn((p-s)*(e-s)) < || sgn((p-e)*(s-e)) < )
return min(p.distance(s),p.distance(e));
return dispointtoline(p);
}
};
const int MAXN = ;
Line line[MAXN]; double get(int i,double L)
{
double l = , r = L;
while(r - l >= eps)
{
double mid = (l + r)/;
double midmid = (r + mid)/;
if(line[i].dispointtoseg(Point(mid,)) < line[i].dispointtoseg(Point(midmid,)))
r = midmid - eps;
else l = mid + eps;
}
return l;
}
int n;
double L; struct Node
{
double a;
int c;
Node(double _a = ,int _c = )
{
a = _a;
c = _c;
}
};
bool cmp(Node a,Node b)
{
if(sgn(a.a - b.a) != )return a.a < b.a;
else return a.c > b.c;
} double bin1(int i,double l,double r,double R)
{
while(r-l >= eps)
{
double mid = (l+r)/;
if(line[i].dispointtoseg(Point(mid,)) <= R)
r = mid - eps;
else l = mid + eps;
}
return l;
}
double bin2(int i,double l,double r,double R)
{
while(r-l >= eps)
{
double mid = (l+r)/;
if(line[i].dispointtoseg(Point(mid,)) <= R)
l = mid + eps;
else r = mid - eps;
}
return l;
} bool gao(double r)
{
vector<Node>vec;
for(int i = ;i < n;i++)
{
double tmp = get(i,L);
if(sgn(line[i].dispointtoseg(Point(tmp,)) - r) >= )
{
vec.push_back(Node(,));
vec.push_back(Node(L,-));
continue;
}
if(sgn(line[i].dispointtoseg(Point(,)) - r) >= )
{
double tt = bin1(i,,tmp,r);
vec.push_back(Node(,));
vec.push_back(Node(tt,-));
}
if(sgn(line[i].dispointtoseg(Point(L,)) - r) >= )
{
double tt = bin2(i,tmp,L,r);
vec.push_back(Node(tt,));
vec.push_back(Node(L,-));
}
}
sort(vec.begin(),vec.end(),cmp);
int cnt = ;
for(int i = ;i < vec.size();i++)
{
cnt += vec[i].c;
if(cnt >= n)return true;
}
return false;
} double solve()
{
double l = , r = inf;
while(r-l >= eps)
{
double mid = (l+r)/;
if(gao(mid))l = mid+eps;
else r = mid - eps;
}
return l;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%lf",&n,&L);
for(int i = ;i < n;i++)
line[i].input();
printf("%.3lf\n",solve());
}
return ;
}
UVALive 4818 - Largest Empty Circle on a Segment (计算几何)的更多相关文章
- 4818 Largest Empty Circle on a Segment (几何+二分)
ACM-ICPC Live Archive 挺水的一道题,直接二分圆的半径即可.1y~ 类似于以前半平面交求核的做法,假设半径已经知道,我们只需要求出线段周围哪些位置是不能放置圆心的即可.这样就转换为 ...
- uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)
题目链接:uva 1463 - Largest Empty Circle on a Segment 二分半径,对于每一个半径,用三分求出线段到线段的最短距离,依据最短距离能够确定当前R下每条线段在[0 ...
- Visulalize Boost Voronoi in OpenSceneGraph
Visulalize Boost Voronoi in OpenSceneGraph eryar@163.com Abstract. One of the important features of ...
- Voronoi Diagram——维诺图
Voronoi图定义 任意两点p 和q 之间的欧氏距离,记作 dist(p, q) .就平面情况而言,我们有 dist(p, q) = (px-qx)2+ (py-qy)2 ...
- Apache Kafka – KIP 32,33 Time Index
32, 33都是和时间相关的, KIP-32 - Add timestamps to Kafka message 引入版本,0.10.0.0 需要给kafka的message加上时间戳,这样更方便一些 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- BUAA_2020_软件工程_结对项目作业
项目 内容 这个作业属于哪个课程 班级博客 这个作业的要求在哪里 作业要求 我在这个课程的目标是 掌握软件工程的思路方法 这个作业在哪个具体方面帮助我实现目标 学习结对编程 教学班级 006 项目地址 ...
- zw版_zw中文增强版Halcon官方Delphi例程
[<zw版·delphi与halcon系列原创教程>zw版_zw中文增强版Halcon官方Delphi例程 源码下载:http://files.cnblogs.com/files/ziwa ...
随机推荐
- 《C与指针》第一章练习
本章例程 程序1.1 重排字符 #include <stdio.h> #include <stdlib.h> #include <string.h> #define ...
- 论文笔记之:Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks
Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks NIPS 2015 摘要:本文提出一种 ...
- Java--RuntimeException(运行时异常)
[转载自]:http://blog.csdn.net/qq7342272/article/details/7940741 java运行时异常是可能在java虚拟机正常工作时抛出的异常. java提供了 ...
- ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十四)之漏掉的客服消息
前言 不知不觉已经十四篇了,其实已经没有什么可写了.但是突然发现layim中带的客服功能没有用到.于是乎,抽点时间完成吧.其实之前的工作已经把客服功能完成了一大半,剩下的我们稍微调整即可.今天的演示我 ...
- loose coupling之函数签名
当函数的参数有多个时(比如多于4个),可以考虑将这些参数组织放入一个class(struct),然后函数参数就减少为一个. 1.以class instance来穿参数,可以很容易在各个函数之间传递参数 ...
- [zz] be similar with和be similar to的区别
http://wenda.tianya.cn/question/4cb13da080ee34c9 be similar to后边既可以加物主代词又可以加人,即:be similar to sth/sb ...
- Navicat(连接) -1之SSH 设置
SSH 设置 Secure SHell (SSH) 是一个通过网络登录其他计算机的程序,在远程服务器运行命令,和从一台机器移动文件到另一台.在不安全的网络中,它提供两台主机之间强大认证和安全加密的的通 ...
- Object类概述
Object:类 Object 是类层次结构的根类.每个类都使用 Object 作为超类.每个类都直接或者间接的继承自Object类. Object类的方法:public int hashCode() ...
- #ifdef #ifndef使用
#ifdef THREAD_ON while (TRUE) #endif 如上没定义THREAD_ON时,是不会跑到while中去的 如上没定义THREAD_ON时,是会跑到else中去的 #ifnd ...
- sp_help 快速查看表结构、视图信息
sp_helptext: 是MS SQL Server的一个系统存储过程,可以通过它来查看存储过程或者视图.函数源码 示例:sp_helptext viewName (viewName 即要查询的存 ...