ZOJ 旋转卡壳 3762 Pan's Labyrinth

来源:互联网 发布:大数据金融行业运用 编辑:程序博客网 时间:2024/05/23 23:49
Pan's Labyrinth

 


 

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

 


 

Ofelia is chased by her evil stepfather, and now she finds herself lost in a labyrinth. She needs your help to run away from her tragic family.

There's a huge metal door standing in front of the exit of the labyrinth. There are n dots on the metal door. Pan (the god of the labyrinth) asks Ofelia to find out a triangle which has the largest height. The triangle's three vertexes must be the dots on the door, and its area must be positive. Ofelia should tell Pan the triangle's height so Pan will let Ofelia go.

Input

There are multiple cases (About 100 cases). For each case, the first line contains an integer n (3<=n<=500). In the next n lines, each line contains two real number x[i], y[i] (0<=x[i], y[i]<=10000) which indicates each dot's coordinate. There is no two dots in the same coordinate. The answers are strictly greater than 0.

Output

For each test case, output one line with the maximum triangle height. Any solution with a relative or absolute error of at most 1e-6 will be accepted.

Sample Input

60.000 4.0002.000 4.0001.000 0.0001.000 8.0000.900 7.0001.100 7.00076967.54555 3457.712003.52325 1273.859127755.35733 9812.97643753.00303 2124.709377896.71246 8877.780545832.77264 5213.704784629.38110 8159.01498

Sample Output

7.000008940.96643

Hint

In case 1. Choose the dot 3, 5, 6 to make up a triangle, and this triangle has the largest height 7.000. In case 2. We choose dot 2, 3, 5.


 

题意:给出一个点集,求出高最大的三角形的高。

 

思路:http://blog.csdn.net/accelerator_916852/article/details/20394799

 

代码:

#include<iostream>#include<cstdio>#include<vector>#include<string.h>#include<cmath>#include<algorithm>#include<cstring>using namespace std;#define eps 1e-8inline double min(double a, double b) { return a < b ? a : b; }inline double max(double a, double b) { return a > b ? a : b; }inline double min(double a, double b, double c) { return min(a, min(b, c)); }int dcmp(double a, double b){if (a<b - eps) return -1;else if (a>b + eps) return 1;return 0;}struct Point{double x, y;Point(double x = 0, double y = 0):x(x), y(y) { }bool operator<(const Point&p) const{return dcmp(x, p.x)<0 || (dcmp(x, p.x) == 0 && y<p.y);}bool operator==(const Point&p) const{return dcmp(x, p.x) == 0 && dcmp(y, p.y) == 0;}};typedef Point Vector;Vector operator+(const Vector&a, const Vector&b) { return Vector(a.x + b.x, a.y + b.y); }Vector operator-(const Vector&a, const Vector&b) { return Vector(a.x - b.x, a.y - b.y); }Vector operator*(const Vector&a, double x) { return Vector(a.x*x, a.y*x); }double Dot(const Vector&a, const Vector& b) { return a.x*b.x + a.y*b.y; }double Cross(const Vector&a, const Vector&b) { return a.x*b.y - a.y*b.x; }double Distance(const Point&a, const Point&b) { return sqrt(Dot(a - b, a - b)); }int Convexhull(Point*p, int n, Point* ch){sort(p, p + n);n = unique(p, p + n) - p;int m = 0;for (int i = 0; i<n; ++i) {while (m>1 && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 1])<eps) --m;ch[m++] = p[i];}int k = m;for (int i = n - 2; i >= 0; --i) {while (m>k&&Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 1])<eps) --m;ch[m++] = p[i];}if (n>1) --m;return m;}struct Line{Point a, b;Vector v;double ang;Line() { }Line(Point a, Point b):a(a), b(b) { v = b - a; ang = atan((a.y - b.y) / (a.x - b.x)); }bool operator<(const Line&Le) const { return ang < Le.ang; }};bool OnLeft(const Point&a, const Line&L) { return Cross(a - L.a, L.v) > eps; }bool OnRight(const Point&a, const Line&L) { return Cross(a - L.a, L.v) < -eps; }const int maxn = 500 + 5;Point p[maxn], hull[maxn];Line L[maxn][maxn*2];int line_cnt;int n;double Rotate(int m){double ans = 0;hull[m] = hull[0];for (int i = 0; i < n; ++i) {int k = 0;for (int j = 0; j < n-1; ++j) {while (OnRight(hull[k], L[i][j])) k = (k + 1) % m;while (hull[k] == L[i][j].a || hull[k] == L[i][j].b) k = (k + 1) % m;while (dcmp(Cross(L[i][j].v, hull[k + 1] - L[i][j].a), Cross(L[i][j].v,hull[k]-L[i][j].a))>0) k = (k + 1) % m;double d = Distance(L[i][j].a, L[i][j].b);double h = Cross(L[i][j].v, hull[k] - L[i][j].a) / d;if (h>ans) ans = h;}}return ans;}void input(){for (int i = 0; i < n; ++i) scanf("%lf%lf", &p[i].x, &p[i].y);line_cnt = 0;for (int i = 0; i < n; ++i) {int cnt = 0;for (int j = 0; j < n; ++j) if (i != j)L[i][cnt++] = Line(p[i], p[j]);sort(L[i], L[i] + cnt);}}void solve(){int m = Convexhull(p, n, hull);double ans = Rotate(m);printf("%.7lf\n", ans);}int main(){while (scanf("%d", &n) == 1){input();solve();}}


 

 

0 0
原创粉丝点击