hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
2014-08-16 16:38
429 查看
链接:http://poj.org/problem?id=2079
Triangle
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 −104<= xi, yi <= 104 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
Sample Output
Source
Shanghai 2004 Preliminary
--------------------------------------------------------------------------------------------------------------------------
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
乱起八糟的凸包,参考了n个凸包构建,但是构建方式都不同,有的凸包都还倒过来扫一遍,,,,,,不知道其中的差别
还有叉乘,叉乘没有深入理解
旋转卡壳还要重新看
View Code
Triangle
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 8173 | Accepted: 2423 |
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 −104<= xi, yi <= 104 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
--------------------------------------------------------------------------------------------------------------------------
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
乱起八糟的凸包,参考了n个凸包构建,但是构建方式都不同,有的凸包都还倒过来扫一遍,,,,,,不知道其中的差别
还有叉乘,叉乘没有深入理解
旋转卡壳还要重新看
#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> using namespace std; #define eps 1e-8 #define MAXX 1000010 typedef struct point { double x; double y; }point; bool dy(double x,double y){ return x>y+eps; } bool xy(double x,double y){ return x<y-eps; } bool dyd(double x,double y){ return x>y-eps; } bool xyd(double x,double y){ return x<y+eps; } bool dd(double x,double y){ return fabs(x-y)<eps; } double crossProduct(point a,point b,point c) { return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x); } double dist(point a,point b) { return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)); } point c[MAXX]; point stk[MAXX]; int top; bool cmp(point a,point b) { double len=crossProduct(c[0],a,b); if(dd(len,0.0)) return xy(dist(c[0],a),dist(c[0],b)); return xy(len,0.0); } double max(double x,double y) { return xy(x,y) ? y : x; } void Graham(int n) { int tmp=0; for(int i=1; i<n; i++) { if(xy(c[i].x,c[tmp].x) || dd(c[i].x,c[tmp].x) && xy(c[i].y,c[tmp].y)) tmp=i; } swap(c[0],c[tmp]); sort(c+1,c+n,cmp); stk[0]=c[0]; stk[1]=c[1]; top=1; for(int i=2; i<n; i++) { while(top>=1 && xyd(crossProduct(stk[top],stk[top-1],c[i]),0.0)) top--; stk[++top]=c[i]; } } double rotating(int n) { int j=1,k=2; double ans=0.0; stk =stk[0]; for(int i=0; i<n; i++) { while(dy(fabs(crossProduct(stk[(k+1)%n],stk[i],stk[j])),fabs(crossProduct(stk[k],stk[i],stk[j])))) k=(k+1)%n; while(dy(fabs(crossProduct(stk[k],stk[i],stk[(j+1)%n])),fabs(crossProduct(stk[k],stk[i],stk[j])))) j=(j+1)%n; ans=max(ans,fabs(crossProduct(stk[k],stk[i],stk[j]))); } return ans*0.5; } int main() { int i,j,n; while(scanf("%d",&n)!=EOF&&n != -1) { for(i=0; i<n; i++) scanf("%lf%lf",&c[i].x,&c[i].y); Graham(n);//printf("%d**",top); double ans=rotating(top+1); printf("%.2lf\n",ans); } return 0; }
View Code
相关文章推荐
- POJ 2079 Triangle(凸包_旋转卡壳之最大三角形面积)
- poj 2079(旋转卡壳求解凸包内最大三角形面积)
- POJ 2079 Triangle (凸包中的最大三角形&旋转卡壳)
- POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
- POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
- poj 2079 Triangle 凸包+旋转卡壳 求最大三角形面积
- POJ 2079 求最大三角形面积 (凸包+旋转卡壳)
- POJ 2079 Triangle(凸包+旋转卡壳求最大三角形面积)
- POJ 2079 Triangle(旋转卡壳计算平面点集最大三角形面积)
- POJ 2079 Triangle (平面点最大三角形 凸包+旋转卡壳 推荐)
- HDU 3934 Summer holiday 旋转卡壳 最大三角形面积
- poj2079凸包求最大三角形面积
- ZOJ 2419-- Triangle-凸包+旋转卡壳求最大面积三角形(计算几何)
- poj2079 Triangle (旋转卡壳之最大三角形)
- HDOJ 2202 最大三角形 凸包旋转卡壳求最大三角形面积
- poj 2079 Triangle,旋转卡壳求点集的最大三角形
- poj 2079 Triangle,旋转卡壳求点集的最大三角形
- HDU 2202 最大三角形 (凸包+旋转卡壳)
- hdu 最大三角形(凸包+旋转卡壳)
- 强大的旋转卡壳 POJ 2187 最远点对 POJ 2079点集中面积最大的三角形