链接:http://poj.org/problem?id=2079
Triangle
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 8173   Accepted: 2423

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

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

 
--------------------------------------------------------------------------------------------------------------------------
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
乱起八糟的凸包,参考了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[],a,b);
if(dd(len,0.0))
return xy(dist(c[],a),dist(c[],b));
return xy(len,0.0);
} double max(double x,double y)
{ return xy(x,y) ? y : x;
} void Graham(int n)
{ int tmp=;
for(int i=; 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[],c[tmp]);
sort(c+,c+n,cmp);
stk[]=c[];
stk[]=c[];
top=;
for(int i=; i<n; i++)
{
while(top>= && xyd(crossProduct(stk[top],stk[top-],c[i]),0.0))
top--;
stk[++top]=c[i];
}
} double rotating(int n)
{
int j=,k=;
double ans=0.0;
stk[n]=stk[];
for(int i=; i<n; i++)
{
while(dy(fabs(crossProduct(stk[(k+)%n],stk[i],stk[j])),fabs(crossProduct(stk[k],stk[i],stk[j]))))
k=(k+)%n;
while(dy(fabs(crossProduct(stk[k],stk[i],stk[(j+)%n])),fabs(crossProduct(stk[k],stk[i],stk[j]))))
j=(j+)%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 != -)
{ for(i=; i<n; i++)
scanf("%lf%lf",&c[i].x,&c[i].y);
Graham(n);//printf("%d**",top);
double ans=rotating(top+);
printf("%.2lf\n",ans);
}
return ;
}

hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)的更多相关文章

  1. POJ 2079 Triangle 旋转卡壳求最大三角形

    求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...

  2. bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积

    在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...

  3. POJ 2187 凸包+旋转卡壳

    思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说   凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...

  4. CodeForces - 682E: Alyona and Triangles(旋转卡壳求最大三角形)

    You are given n points with integer coordinates on the plane. Points are given in a way such that th ...

  5. POJ 2079 Triangle [旋转卡壳]

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9525   Accepted: 2845 Descript ...

  6. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  7. Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)

    题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...

  8. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  9. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

随机推荐

  1. android 项目学习随笔十八(三级缓存)

    xUtils的BitmapUtils模块用的就是三级缓存,在项目中尽量还是应用BitmapUtils 三级缓存(机制) import com.itheima.zhsh66.R; import andr ...

  2. LoadRunner并发用户和集合点的深入讨论

    看到51上三个高手Zee, 大漠飞鹰,xingcyx的一场非常精彩的关于并发用户数和集合点的讨论,很有意义.如果对这两个概念不清楚的朋友,一定要仔细领悟了. 故事开始于xingcyx的一番话: 声明: ...

  3. Delphi中CoInitialize之探究

    CoInitialize(LPVOID),它将以特定参数调用CoInitializeEx,为当前单元初始化COM库,并标记协同模式为单线程模式.参数必须为NULL.这是关于OLE和COM的问题. Co ...

  4. linux内核参数优化

    net.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route ...

  5. Java Properties工具类详解

    1.Java Properties工具类位于java.util.Properties,该工具类的使用极其简单方便.首先该类是继承自 Hashtable<Object,Object> 这就奠 ...

  6. React Native 开发笔记

    ReactNativeDemo 学习ReactNative开发,搭建ReactNative第一个项目 React Native 开发笔记 1.安装Homebrew $ /usr/bin/ruby -e ...

  7. PHP操作Memcache基本函数的方法

    Memcache基本函数. Memcache ― Memcache类 Memcache::add ― 增加一个条目到缓存服务器 Memcache::addServer ― 向连接池中添加一个memca ...

  8. ecshop编辑器fckeditor换百度ueditor编辑器教程

    1.下载uediter编辑器,解压上传目录uediter到根目录/includes/下   2.修改admin/includes/lib_main.php         /**   * 生成编辑器  ...

  9. 结对2.0--复利计算WEB升级版

    结对2.0--复利计算WEB升级版 复利计算再升级------------------------------------------------------------ 客户在大家的引导下,有了更多 ...

  10. POJ 2406:Power Strings

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41252   Accepted: 17152 D ...