ACM-ICPC Live Archive

  挺水的一道题,直接二分圆的半径即可。1y~

  类似于以前半平面交求核的做法,假设半径已经知道,我们只需要求出线段周围哪些位置是不能放置圆心的即可。这样就转换为圆与直线,直线与直线交的问题了。

  不知道这题能不能SAA过,有空试下。

代码如下:

 #include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const double EPS = 1e-;
inline int sgn(double x) { return (x > EPS) - (x < -EPS);}
typedef pair<double, double> Point;
#define x first
#define y second
template<class T> T sqr(T x) { return x * x;}
Point operator + (Point a, Point b) { return Point(a.x + b.x, a.y + b.y);}
Point operator - (Point a, Point b) { return Point(a.x - b.x, a.y - b.y);}
Point operator * (Point a, double p) { return Point(a.x * p, a.y * p);}
Point operator / (Point a, double p) { return Point(a.x / p, a.y / p);} inline double cross(Point a, Point b) { return a.x * b.y - a.y * b.x;}
inline double dot(Point a, Point b) { return a.x * b.x + a.y * b.y;}
inline double veclen(Point a) { return sqrt(dot(a, a));}
inline Point vecunit(Point a) { return a / veclen(a);}
inline Point normal(Point a) { return Point(-a.y, a.x) / veclen(a);} struct Line {
Point s, t;
Line() {}
Line(Point s, Point t) : s(s), t(t) {}
Point vec() { return t - s;}
Point point(double p) { return s + vec() * p;}
Line move(double p) { // + left - right
Point nor = normal(vec());
return Line(s + nor * p, t + nor * p);
}
} ; inline bool between(Point o, Point a, Point b) { return sgn(dot(a - o, b - o)) < ;}
inline bool between(Point a, Line l) { return between(a, l.s, l.t);}
inline Point llint(Line a, Line b) { return a.point(cross(b.vec(), a.s - b.s) / cross(a.vec(), b.vec()));} bool clint(Point a, double r, double *sol) {
if (sgn(r - fabs(a.y)) <= ) return ;
double d = sqrt(sqr(r) - sqr(a.y));
//cout << "d " << d << endl;
sol[] = a.x - d;
sol[] = a.x + d;
return ;
} Line Y0 = Line(Point(, ), Point(, )); double L;
inline void adjust(double &x) { x = max(0.0, min(L, x));}
Point getseg(Line a, double r) {
vector<double> sol;
sol.clear();
double t[];
if (clint(a.s, r, t)) sol.push_back(t[]), sol.push_back(t[]);
if (clint(a.t, r, t)) sol.push_back(t[]), sol.push_back(t[]);
Line l1 = a.move(r), l2 = a.move(-r), l3 = Line(l1.s, l2.s), l4 = Line(l1.t, l2.t);
Point p1 = llint(l1, Y0), p2 = llint(l2, Y0), p3 = llint(l3, Y0), p4 = llint(l4, Y0);
if (between(p1, l1)) sol.push_back(p1.x);
if (between(p2, l2)) sol.push_back(p2.x);
if (between(p3, l3)) sol.push_back(p3.x);
if (between(p4, l4)) sol.push_back(p4.x);
if (sol.size() == ) return Point(-, -);
sort(sol.begin(), sol.end());
//cout << "sol ";
//for (int i = 0; i < sol.size(); i++) cout << sol[i] << ' '; cout << endl;
adjust(sol[]), adjust(sol[sol.size() - ]);
return Point(sol[], sol[sol.size() - ]);
} const int N = ;
typedef pair<double, int> Event;
Line l[N];
int n; bool test(double r) {
vector<Event> ev;
ev.clear();
for (int i = ; i < n; i++) {
Point tmp = getseg(l[i], r);
if (tmp.x < || tmp.y < ) continue;
//cout << tmp.x << '~' << tmp.y << endl;
ev.push_back(Event(tmp.x, ));
ev.push_back(Event(tmp.y, -));
}
sort(ev.begin(), ev.end());
//cout << r << endl;
//for (int i = 0; i < ev.size(); i++) cout << ev[i].x << '&' << ev[i].y << ' '; cout << endl;
double last = ;
int cnt = , sz = ev.size();
for (int i = ; i < sz; i++) {
if (ev[i].y == ) {
if (cnt == && sgn(ev[i].x - last) > ) return ;
cnt++;
} else {
if (cnt == ) last = ev[i].x;
cnt--;
}
}
return sgn(L - last) > ;
} int main() {
//freopen("in", "r", stdin);
int T;
cin >> T;
while (T-- && cin >> n >> L) {
for (int i = ; i < n; i++) cin >> l[i].s.x >> l[i].s.y >> l[i].t.x >> l[i].t.y;
double lp = , rp = , mp;
while (rp - lp > EPS) {
mp = (lp + rp) / ;
if (test(mp)) lp = mp;
else rp = mp;
}
//puts("~~~~~~~~~~~~~~~~~~~~~~~~");
//test(2.118);
printf("%.3f\n", mp);
}
return ;
}

——written by Lyon

4818 Largest Empty Circle on a Segment (几何+二分)的更多相关文章

  1. uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)

    题目链接:uva 1463 - Largest Empty Circle on a Segment 二分半径,对于每一个半径,用三分求出线段到线段的最短距离,依据最短距离能够确定当前R下每条线段在[0 ...

  2. UVALive 4818 - Largest Empty Circle on a Segment (计算几何)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  3. Project Euler 363 Bézier Curves(几何+二分)

    题目链接: https://projecteuler.net/problem=363 题目: A cubic Bézier curve is defined by four points: \(P_0 ...

  4. BZOJ-1822 Frozen Nova 冷冻波 计(jie)算(xi)几何+二分+最大流判定+经典建图

    这道逼题!感受到了数学对我的深深恶意(#‵′).... 1822: [JSOI2010]Frozen Nova 冷冻波 Time Limit: 10 Sec Memory Limit: 64 MB S ...

  5. UVALive - 6856 Circle of digits 后缀数组+二分

    题目链接: http://acm.hust.edu.cn/vjudge/problem/82135 Circle of digits Time Limit: 3000MS 题意 把循环串分割成k块,让 ...

  6. 【BZOJ1822】[JSOI2010]Frozen Nova 冷冻波 几何+二分+网络流

    [BZOJ1822][JSOI2010]Frozen Nova 冷冻波 Description WJJ喜欢“魔兽争霸”这个游戏.在游戏中,巫妖是一种强大的英雄,它的技能Frozen Nova每次可以杀 ...

  7. Aquarium Tank(csu1634+几何+二分)Contest2087 - 湖南多校对抗赛(2015.05.24)-G

    Aquarium Tank Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 15  Solved: 4[Submit][Status][Web Board ...

  8. poj 2002 Squares 几何二分 || 哈希

    Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 15137   Accepted: 5749 Descript ...

  9. Visulalize Boost Voronoi in OpenSceneGraph

    Visulalize Boost Voronoi in OpenSceneGraph eryar@163.com Abstract. One of the important features of ...

随机推荐

  1. java 的安装

    下载 java的官方下载地址:https://www.java.com/zh_CN/ 安装 下载完成后,可以按照默认安装路径,也可以自行设置安装路径.例如我的安装路径为:D:\Program File ...

  2. c#多线程通信之委托(事件)

    在研究c# 线程之间通信时,发现传统的方法大概有三种 ①全局变量,由于同一进程下的多个进程之间共享数据空间,所以使用全局变量是最简单的方法,但要记住使用volatile进行限制. ②线程之间发送消息( ...

  3. java并发系列(八)-----java异步编程

    同步计算与异步计算 从多个任务的角度来看,任务是可以串行执行的,也可以是并发执行的.从单个任务的角度来看,任务的执行方式可以是同步的,也可以是异步的. Runnable.Callable.Future ...

  4. Xshell 、PuTTY 复制文件到Linux

    一.使用Xshell 在linux下下载一个需要安装一个工具lrzsz包: [root@localhost home] # yum install -y lrzsz 从windows上传文件到linu ...

  5. Python3入门机器学习 经典算法与应用

    Python3入门机器学习 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题,大家看的时候可以关注下 ...

  6. Vue.之.项目开发工具选用

    Vue.之.项目开发工具选用 上篇文章记录了创建项目,这篇文件记录,如何对创建的项目进行开发.这里选择一个工具:Visual Studio Code (请自行下载安装) 1. 打开VSCode工具,并 ...

  7. python 处理缺失值

  8. NOIP模拟 7.01

    水灾(sliker.cpp/c/pas) 1000MS  64MB 大雨应经下了几天雨,却还是没有停的样子.土豪CCY刚从外地赚完1e元回来,知道不久除了自己别墅,其他的地方都将会被洪水淹没. CCY ...

  9. Ubuntu上更换163源 - Mars Loo的博客

    转载*请注明原始出处:http://blog.csdn.net/a464057216/article/details/50865895 先备份源/etc/apt/sources.list为source ...

  10. iview 中table列 一列显示多个数据(后台返回数组显示在列内)

    一.首先出现的是比较复杂的一种情况(多个key) 1.首先页面显示效果如下 2.后台返回数据格式如下: 3.在iview中table的columns中的render函数: 4.具体代码 render: ...