[POJ]3525 半平面交
来源:互联网 发布:linux查看文件 编辑:程序博客网 时间:2024/06/06 03:55
Description
The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: “Where is the most distant point from the sea?” The answer to this question for Honshu was found in 1996. The most distant point is located in former Usuda Town, Nagano Prefecture, whose distance from the sea is 114.86 km.
In this problem, you are asked to write a program which, given a map of an island, finds the most distant point from the sea in the island, and reports its distance from the sea. In order to simplify the problem, we only consider maps representable by convex polygons.
Input
The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows.
Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space.
n in the first line is the number of vertices of the polygon, satisfying 3 ≤ n ≤ 100. Subsequent n lines are the x- and y-coordinates of the n vertices. Line segments (xi, yi)–(xi+1, yi+1) (1 ≤ i ≤ n − 1) and the line segment (xn, yn)–(x1, y1) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive.
You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.
The last dataset is followed by a line containing a single zero.
Output
For each dataset in the input, one line containing the distance of the most distant point from the sea should be output. An output line should not contain extra characters such as spaces. The answer should not have an error greater than 0.00001 (10−5). You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.
Sample Input
40 010000 010000 100000 1000030 010000 07000 100060 40100 20250 40250 70100 900 7030 010000 100005000 50010
Sample Output
5000.000000494.23364134.5429480.353553
Source
[Submit] [Go Back] [Status] [Discuss]
Home Page Go Back To top
大括号决定不再提行了。。 要不然写只有一行的函数要死人... 发现空一格换行也挺错落有致的... 话说博客终于破两百篇了~
这道题让你求离海最远的距离, 其实就是求内切圆... 二分答案来缩小收缩各边... 然后判断有无半平面交即可. 算几的模板好长啊不过还是蛮好看的, 也还蛮好写。 只能期待指法练成有一个强大的代码能力了~ 突然想起上次东北集训有幸liu_runda学长帮我查错, 目睹了什么叫真正的手速...
#include<stdio.h>#include<cmath>#include<vector>#include<algorithm>using namespace std;const double eps = 1e-8;const int maxn = 1e5;int n;inline int sign(double x) {return (x > -eps) - (x < eps);}struct Vector {double x, y;Vector(){}Vector(double x, double y) : x(x), y(y) {}double ang() const {return atan2(y, x);}double len() const {return sqrt(x * x + y * y);}inline friend bool operator < (const Vector &r, const Vector &s) {return r.x < s.x || (r.x == s.x && r.y < s.y);}inline friend Vector operator + (const Vector &r, const Vector &s) {return Vector(r.x + s.x, r.y + s.y);}inline friend Vector operator - (const Vector &r, const Vector &s) {return Vector(r.x - s.x, r.y - s.y);}inline friend Vector operator * (const Vector &r, double s) {return Vector(r.x * s, r.y * s);}inline friend Vector operator / (const Vector &r, double s) {return Vector(r.x / s, r.y / s);}};typedef Vector Point;inline double cross(const Vector &r, const Vector &s) {return r.x * s.y - r.y * s.x;}inline double dot(const Vector &r, const Vector &s) {return r.x * s.x + r.y * s.y;}inline Vector normal(const Vector &u) {return Vector(-u.y, u.x);}inline Vector zoom(const Vector &u, double s) {return u * (s / u.len());}struct Line {Point p;Vector u;double ang;Line(){}Line(Point p, Vector u) : p(p), u(u), ang(u.ang()) {}inline friend bool operator < (const Line &r, const Line &s) {return r.ang < s.ang;}inline friend bool operator == (const Line &r, const Line &s) {return ! sign(r.ang - s.ang);}};inline bool onleft (const Line &l, const Point &p) {return cross(l.u, p - l.p) > 0; }inline bool parallel(const Line &r, const Line &s) {return fabs(cross(r.u, s.u)) < eps;}inline Point Line_intersect(const Point &P, const Vector &u, const Point &Q, const Vector &v) {double t = cross(Q - P, v) / cross(u, v);return P + u * t;}inline Point Line_intersect(const Line &r, const Line &s) {return Line_intersect(r.p, r.u, s.p, s.u);}Line q[maxn];Point p[maxn];vector<Line> h;inline int half_plane_intersect() {sort(h.begin(), h.end());int n = h.size();int first, last;q[first = last = 0] = h[0];for (int i = 1; i < n; ++ i) {while (first < last && ! onleft(h[i], p[last - 1])) last --;while (first < last && ! onleft(h[i], p[first])) first --;q[++ last] = h[i];if (parallel(q[last - 1], q[last])) {last --;if (onleft(q[last], h[i].p)) q[last] = h[i];}if (first < last) p[last - 1] = Line_intersect(q[last], q[last - 1]);}while (first < last && ! onleft(q[first], p[last - 1])) first ++;if (last - first <= 1) return 0;p[last] = Line_intersect(q[first], q[last]);return last - first + 1;}vector<Point> cvx;inline bool check(double mid) {h.clear();Point a, b;for (int i = 0; i < n; ++ i) {a = cvx[i];b = cvx[(i + 1) % n];Vector u = zoom(normal(b - a), mid);h.push_back(Line(a + u, b - a));}return half_plane_intersect();}int main() {while (scanf("%d", &n) && n) {cvx.clear();for (int i = 0; i < n; ++ i) {double x, y;scanf("%lf%lf", &x, &y);cvx.push_back(Point(x, y));}double lf = 0, rg = 20000.0;while (lf + eps < rg) {double mid = (lf + rg) / 2.0;if (check(mid)) lf = mid;else rg = mid;}printf("%.6f\n", lf);}}
- POJ 3525 半平面交
- POJ 3525 半平面交
- [POJ]3525 半平面交
- poj 3525 二分+半平面交
- POJ 3525 二分+半平面交
- 半平面交 poj 3335(判断是否有内核) poj 3525 (半平面交+二分)
- POJ 3384 半平面交
- POJ 1755 半平面交
- POJ 2540 半平面交
- poj 3335(半平面交)
- 【poj 2451】半平面交
- 半平面交 (POJ 1279
- POJ 3525 二分答案,推进多边形和半平面交
- POJ 3525 二分答案,推进多边形和半平面交
- POJ 3525/LA 3890 二分+半平面交
- poj 2451 (半平面求交)
- POJ 1755 Triathlon 半平面交
- POJ 3384 Feng Shui(半平面交)
- JavaScript BOM
- Android Drawable之 Ripple的使用
- STL中的set容器的一点总结
- 牛客网初级班(2)
- C#算法系列(7)——快速排序
- [POJ]3525 半平面交
- TinyPng批量压缩Python脚本
- MySql常用命令和语法以及可视化工具Navicat的使用
- hdu1251统计难题
- HEVC编码结构
- Kettle实现行转列1(场景)
- Windows安装Mysql客户端
- Python自然语言处理工具小结
- springMVC分页显示