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

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


选三个点三角形面积最大

这三个点一定在凸包上

可以O(n),猜i,j,k单调,然后和旋转卡壳一样枚举i,先让k跑,再让j跑

事实证明貌似真的单调,discuss里的数据并不能卡掉我的程序....

注意:跑的时候用面积判断是不是跑到下一个

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=5e4+;
const double eps=1e-; inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
} struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return sgn(x-a.x)<||(sgn(x-a.x)==&&sgn(y-a.y)<);
}
};
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 b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;} double Len(Vector a){return sqrt(Dot(a,a));}
double Len2(Vector a){return Dot(a,a);}
double DisTL(Point p,Point a,Point b){
Vector v1=p-a,v2=b-a;
return abs(Cross(v1,v2)/Len(v2));
}
int ConvexHull(Point p[],int n,Point ch[]){
sort(p+,p++n);
int m=;
for(int i=;i<=n;i++){
while(m>&&sgn(Cross(ch[m]-ch[m-],p[i]-ch[m-]))<=) m--;
ch[++m]=p[i];
}
int k=m;
for(int i=n-;i>=;i--){
while(m>k&&sgn(Cross(ch[m]-ch[m-],p[i]-ch[m-]))<=) m--;
ch[++m]=p[i];
}
if(n>) m--;
return m;
}
double RotatingCalipers(Point p[],int n){
if(n<=) return ;
if(n==) return abs(Cross(p[]-p[],p[]-p[]));
int j=,k=;
double ans=;
p[n+]=p[];
for(int i=;i<=n;i++){
while(sgn(DisTL(p[k],p[i],p[j])-DisTL(p[k+],p[i],p[j]))<=) k=k%n+;
//while(sgn(abs(Cross(p[k]-p[i],p[k]-p[j]))-abs(Cross(p[k+1]-p[i],p[k+1]-p[j])))<=0) k=k%n+1;
ans=max(ans,abs(Cross(p[k]-p[i],p[k]-p[j])));
//while(sgn(DisTL(p[k],p[i],p[j])-DisTL(p[k],p[i],p[j+1]))<=0) j=j%n+1;
while(abs(Cross(p[k]-p[i],p[k]-p[j]))-abs(Cross(p[k]-p[i],p[k]-p[j+]))<=) j=j%n+;
ans=max(ans,abs(Cross(p[k]-p[i],p[k]-p[j])));
}
return ans;
} int n;
Point p[N],ch[N];
int main(int argc, const char * argv[]) {
while(true){
n=read();if(n==-) break;
for(int i=;i<=n;i++) p[i].x=read(),p[i].y=read();
n=ConvexHull(p,n,ch);
double ans=RotatingCalipers(ch,n);
printf("%.2f\n",ans/);
}
}

POJ 2079 Triangle [旋转卡壳]的更多相关文章

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

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

  2. poj 2079 Triangle(旋转卡壳)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 8917   Accepted: 2650 Descript ...

  3. POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 7625   Accepted: 2234 Descript ...

  4. poj 2079 Triangle (二维凸包旋转卡壳)

    Triangle Time Limit: 3000MS   Memory Limit: 30000KB   64bit IO Format: %I64d & %I64u Submit Stat ...

  5. poj 2079 Triangle,旋转卡壳求点集的最大三角形

    给出一个点集,求顶点在点集中的最大的三角形面积. 我们知道这三角形的三个点肯定在凸包上,我们求出凸包之后不能枚举,由于题目n比較大,枚举的话要O(n^3)的数量级,所以採用旋转卡壳的做法: 首先枚举三 ...

  6. ●POJ 2079 Triangle

    题链: http://poj.org/problem?id=2079 题解: 计算几何,凸包,旋转卡壳 复杂度O(N^2),(O(N)什么的就不说了,我觉得我看过的O(N)方法正确性都有问题,虽然有些 ...

  7. POJ 2187 凸包+旋转卡壳

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

  8. POJ 2079 Triangle (凸包+旋转卡壳)

    [题目链接] http://poj.org/problem?id=2079 [题目大意] 给出一些点,求出能组成的最大面积的三角形 [题解] 最大三角形一定位于凸包上,因此我们先求凸包,再在凸包上计算 ...

  9. poj 2079 Triangle

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9835   Accepted: 2951 Descript ...

随机推荐

  1. [国嵌笔记][008-009][远程登录Linux]

    [国嵌笔记][008][远程登录Linux] 1.windows与Linux能够相互ping通 2.关闭Linux防火墙 /etc/init.d/iptables stop 3.通过ssh(字符界面) ...

  2. oracle创建触发器及作用举例

    --创建触发器及作用举例 create or replace trigger tri before delete on emp --在删除emp表数据之前需要做的事根据自己的业务去写,before是在 ...

  3. Java入门篇(五)——Java的字符串/String类

    前面在举例时有出现过String的例子,当时肯定有一部分朋友不知道这个是做什么用的.其实String类是Java中一个比较特殊的类,字符串即String类,它不是Java的基本数据类型之一,但可以像基 ...

  4. URL编码的方法

    Global 对象的encodeURI()和encodeURIComponent()方法可以对URI(Uniform ResourceIdentifiers,通用资源标识符)进行编码,以便发送给浏览器 ...

  5. 番外篇--Moddule Zero介绍

    1.1 ABPZero - 概述 介绍 微软ASP.NET身份框架 权限 会话 角色管理 默认角色 用户管理 多租户 设置管理 审计日志 1.1.1 介绍 Modulde Zero实现了ASP.NET ...

  6. parse_str() 函数把查询字符串解析到变量中。

    注释:如果未设置 array 参数,则由该函数设置的变量将覆盖已存在的同名变量. 注释:php.ini 文件中的 magic_quotes_gpc 设置影响该函数的输出.如果已启用,那么在 parse ...

  7. FileZilla出现Failed to convert command to 8 bit charset 

    FileZilla这款FTP客户端软件,自从华哥使用以来,采用其默认的设置,一直用得很顺畅,没有出现过什么问题.但是今天碰到了一个问题.如图. 错误信息为:Failed to convert comm ...

  8. git只添加指定类型的文件的.gitignore规则

    #忽略根目录下的所有文件 * #忽略子目录下的所有文件 /* #包含目录 !*/ #指定不忽略的文件 !*.c !*.h #忽略根目录下的文件 /build/ /appveyor/ /pear/ /s ...

  9. jsp中${}

    jsp中${}----是EL表达式的常规表示方式目的是为了获取{}中指定的对象(参数.对象等)的值 如:${user.name}<====>User user = (User)reques ...

  10. 注释中不允许出现字符串 "--"。

    问题: 在启动tomcat时会出现如上错误,同时有可能会出现xml无法解析等错误 解决办法: 注释中不能出现字符串 "--",即需要把xml文件中多余的“--”去掉,例如: < ...