poj 2079 Triangle (旋转卡壳)

Triangle
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 9495   Accepted: 2835

Description

Given n distinct points on a plane, your task is to find the triangle that have the maximum area, whose vertices are from the given points.

Input

The input consists of several test cases. The first line of each test case contains an integer n, indicating the number of points on the plane. Each of the following n lines contains two integer xi and yi, indicating the ith points. The last line of the input is an integer −1, indicating the end of input, which should not be processed. You may assume that 1 <= n <= 50000 and −10 4 <= xi, yi <= 10 4 for all i = 1 . . . n.

Output

For each test case, print a line containing the maximum area, which contains two digits after the decimal point. You may assume that there is always an answer which is greater than zero.

Sample Input

3
3 4
2 6
2 7
5
2 6
3 9
2 0
8 0
6 5
-1

Sample Output

0.50
27.00

Source

Shanghai 2004 Preliminary

[Submit]   [Go Back]   [Status]   [Discuss]


题目大意:求以给出的点为顶点的三角形的最大面积。

题解:旋转卡壳

固定i,j两个顶点后,k的位置是单调的

#include
#include
#include
#include
#include
#define N 50003
#define eps 1e-10
using namespace std;
struct vector {
	double x,y;
	vector (double X=0,double Y=0) {
		x=X,y=Y;
	}
}a[N],ch[N];
typedef vector point;
vector operator -(vector a,vector b){
	return vector (a.x-b.x,a.y-b.y);
}
vector operator +(vector a,vector b){
	return vector (a.x+b.x,a.y+b.y);
}
vector operator *(vector a,double t){
	return vector (a.x*t,a.y*t);
}
bool operator <(vector a,vector b)
{
	return a.x1&&cross(ch[m-1]-ch[m-2],a[i]-ch[m-2])<=0) m--;
		ch[m++]=a[i];
	}
	int k=m;
	for (int i=n-1;i>=1;i--){
		while (m>k&&cross(ch[m-1]-ch[m-2],a[i]-ch[m-2])<=0) m--;
		ch[m++]=a[i]; 
	}
	m--;
}
double rotating()
{
	if (m<=2) return 0; 
	if (m==3) return fabs(cross(ch[1]-ch[0],ch[2]-ch[0]))/2;
	double ans=0;
	int i,j,k;
	for (int i=0;i



你可能感兴趣的:(计算几何)