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. <br>和换行符/n

    我们知道<br>是html的标签,表示文本另起一行.经常在html的body标签里面看到br,起到另起一行的作用. 而换行符\n是javascript的转义字符,表示将输出一个换行符,用于 ...

  2. iFrame 父子窗口通讯

    今天就来说说 iFrame 的父子窗口通讯,关于 iFrame 这里就不陈述了,想要了解的盆友可以百度一下, 由于项目需要,前些天用到了个弹框框架 layer 弹出层,有很多弹出的方式,其中一种就是用 ...

  3. springmvc 使用了登录拦截器之后静态资源还是会被拦截的处理办法

    解决办法 在拦截器的配置里加上静态资源的处理 参考https://www.jb51.net/article/103704.htm

  4. 阿里云maven中央仓库

    1.配置文件路径:config/settings.xml 2.<mirrors>镜像集合中添加镜像 <mirror> <id>alimaven</id> ...

  5. 2019阿里云开年Hi购季基础云产品分会场全攻略!

    2019阿里云云上Hi购季活动已经于2月25日正式开启,从已开放的活动页面来看,活动分为三个阶段: 2月25日-3月04日的活动报名阶段.3月04日-3月16日的新购满返+5折抢购阶段.3月16日-3 ...

  6. 从0开始学习 GitHub 系列之「08.如何发现优秀的开源项目」

    之前发过一系列有关 GitHub 的文章,有同学问了,GitHub 我大概了解了,Git 也差不多会使用了,但是 还是搞不清 GitHub 如何帮助我的工作,怎么提升我的工作效率? 问到点子上了,Gi ...

  7. arcgis几何对象

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 集合-Map 接口

    1. 概述   java.util.Map <K,V>接口是一个顶层接口,里面存放的数据单元是:单对元素: K 表示 描述的键 的类型,Key 的类型: V 表示 描述的值 的类型,Val ...

  9. [java]反射1 2017-06-25 21:50 79人阅读 评论(10) 收藏

    很多东西的实现基础,都是反射,spring的AOP,动态代理等等,下面咱们来学习一下Java的反射 什么是反射? JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于 ...

  10. 洛谷P1541 乌龟棋 [2010NOIP提高组]

    P1541 乌龟棋 题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家 ...