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. javaScript原生定义的函数

    1.JavaScript中的算术运算 包括加(+).减(-).乘(*).除(/)和求余(取模)(%)运算,除了这些基本的运算外,JavaScript还支持更加复杂的算术运算,这些复杂算术运算作为Mat ...

  2. 基于 fireasy 构建的 asp.net core 示例

    最近花时间弄了一个关于fireasy使用的demo,已放到 github 上供大家研究,https://github.com/faib920/zero 该 demo 演示了如何使用 fireasy 创 ...

  3. C#面试常见题目

    1.CTS.CLS.CLR分别作何解释 CTS:Common Type System 通用系统类型.Int32.Int16→int.String→string.Boolean→bool CLS:Com ...

  4. 立即掌握SSM框架的要诀

    ssm框架的总结: 1. 首先是POM.xml 文件的配置,他的作用主要是添加依懒的关系和自动下载相关的包. 2.对jdbc.properties进行配置 ,作用就是连接你的数据库的配置. 3.对接着 ...

  5. 电脑如何防蹭网?使用防蹭网功能杜绝未知设备连接WiFi

    发布时间:2015-09-27 15:24发布者:系统城-shaojing浏览数:733 网络越来越卡?网页打开越来越慢?如果你有以上疑问,那么就要确认自己是不是被"蹭网"了.尽管 ...

  6. ecshop_添加最新评论

    第一步: 在includes/lib_goods.php里面构建自定义函数 代码如下: /**  * 获取最近评论 *  * @return array  */ function get_latest ...

  7. java 三大框架

    SSH即:Spring.Struts.HibernateSpring:功能强大的组件粘合济,能够将你的所有的java功能模块用配置文件的方式组合起来(还让你感觉不到spring的存在)成为一个完成的应 ...

  8. Powerdesigner+PostgreSQL

    1.准备软件 Powerdesigner PostgreSQL PostgreSQL ODBC驱动程序: psqlODBC,网址:http://www.postgresql.org/ftp/odbc/ ...

  9. git分支小问题

    参考网址:http://hbiao68.iteye.com/blog/2055493 1.查看分支 git branch 或者 git branch -v 2.创建一个新的分支 git branch ...

  10. pjax 笔记

    PJAX的基本思路是,用户点击一个链接,通过ajax更新页面变化的部分,然后使用HTML5的pushState修改浏览器的URL地址,这样有效地避免了整个页面的重新加载.如果浏览器不支持history ...