Triangle
| Time Limit: 3000MS |
|
Memory Limit: 30000K |
| Total Submissions: 8437 |
|
Accepted: 2497 |
Description
Given n distinct points on a plane, your task was to find the triangle that has the maximum area, whose vertices was from The given points.
Input
The input consists of several test cases. The first line of all test case contains a integer n, indicating the number of points on the plane. Each of the following n lines contains is an integer xi and Yi, indicating the ith points. The last line of the input was an integer 1, indicating the end of input, which should isn't be processed. Assume that 1 <= n <= 50000 and 104 <= XI, Yi <= 104 for all i = 1 ... n.
Output
For each test case, print a line containing the maximum area, which contains, and then the decimal point. You may assume this there is always a answer which is greater than zero.
Sample Input
33 42 62 752 63 92 08 06 5-1
Sample Output
0.5027.00
Source
Shanghai 2004 Preliminary
The maximum triangular area on a convex hull with a rotating jam.
As long as the rotating jam deformation:
The previous rotation jam is to find the heel point of a point and its neighboring points, and now it is possible to enumerate each of the other points and the heel point of the point when seeking a point.
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath > #include <algorithm> #define EPS 1e-9using namespace std;struct point{double x, y;} A[50005];int N,tail,h[50005];bool CMP (point A,point B) {if (a.x==b.x) return A.y<b.y;return a.x<b.x;} Double Cross (Point A,point b,point c) {return (b.x-a.x) * (C.Y-A.Y)-(B.Y-A.Y) * (c.x-a.x);} void Graham () {sort (a+1,a+1+n,cmp); tail=0;for (int i=1;i<=n;i++) {while (Tail>=2&&cross (a[h[tail-2]],a [H[tail-1]],a[i]) <eps) tail--;h[tail++]=i;} int tmp=tail;h[tail++]=n-1;for (int i=n-2;i;i--) {while (Tail>tmp&&cross (A[h[tail-2]],a[h[tail-1]],a[i]) <eps) tail--;h[tail++]=i;} tail--;} Double Rotating_calipers () {double ans=0.0;for (int i=0;i<tail;i++) {int x=i+1;for (int j=i+1;j<=tail;j++) {while ( Fabs (Cross (a[h[i]],a[h[j]],a[h[x+1])) >fabs (Cross (A[h[i]],a[h[j]],a[h[x])) x= (x+1)%tail;ans=max (Ans,fabs ( Cross (A[h[i]],a[h[j]],a[h[x])));}} return ans/2.000;} int main () { while (scanf ("%d", &n)!=eof) {if (n==-1) break;for (int i=1;i<=n;i++) scanf ("%lf%lf", &a[i].x,&a[i].y); Graham ();p rintf ("%.2lf\n", Rotating_calipers ());} return 0;}
"POJ 2079" Triangle