链接: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. 关于ScrollView中嵌套listview焦点滑动问题 解决

    (第三种,第四种简单推荐使用) 在这里我要提出的是,listview能滚动的前提是:当listview本身的高度小于listview里的子view. 第一种方法 只需在MainActivity中 找到 ...

  2. 关于UIView(转)

    曾经有人这么说过,在iphone里你看到的,摸到的,都是UIView,所以UIView在iphone开发里具有非常重要的作用.那么UIView我们到底知道多少呢.请看看下面的问题, 如果这些你都知道, ...

  3. Python标准库之核心模块学习记录

    内建函数和异常 包括__builtin__模块和exceptions模块 操作系统接口模块 包括提供文件和进程处理功能的os模块,提供平台独立的文件名处理(分拆目录名,文件名,后缀等)的os.path ...

  4. JS调用Java函数--DWR框架

    (1)dwr与ssh框架整合教程dwr框架介绍. DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJA ...

  5. ubuntu下配置java环境【转】

    转自:http://www.cnblogs.com/fnng/archive/2013/01/30/2883815.html 配置JDK环境 下载 登录oracle的网站去下载JDK7 http:// ...

  6. 自动封装Servlet HttpServletRequest请求成为一个POJO对象

    自己写了个小工具类,将Servlet里面的HttpServletRequest请求封装成为一个POJO对象,可以复习一下Java的反射原理,开发中这个没什么用,毕竟都用MVC框架,框架都自带这种功能, ...

  7. Java生产者消费者模型

    在Java中线程同步的经典案例,不同线程对同一个对象同时进行多线程操作,为了保持线程安全,数据结果要是我们期望的结果. 生产者-消费者模型可以很好的解释这个现象:对于公共数据data,初始值为0,多个 ...

  8. BZOJ 1588:营业额统计(Splay)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1588 题意:中文题意. 思路:每一个点每一个点插入Splay,然后插入新的一个点之后,查这个节点的前 ...

  9. php中的curl】php中curl的详细解说

    本文我来给大家详细介绍下cURL的简单的使用方法,下文我将会给大家详细介绍cURL的高级应用, cURL可以使用URL的语法模拟浏览器来传输数据, FTP, FTPS, HTTP, HTTPS, GO ...

  10. mini.open打开窗口时传递参数

    mini.open({ url: "xxx.html", showMaxButton: false, allowResize: false, title: '标题', width: ...