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

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

 
 
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std; struct Point
{
int x,y;
Point(int _x = , int _y = )
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y);
}
int operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
int operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
void input()
{
scanf("%d%d",&x,&y);
}
};
int dist2(Point a,Point b)
{
return (a-b)*(a-b);
}
const int MAXN = ;
Point list[MAXN];
int Stack[MAXN],top;
bool _cmp(Point p1,Point p2)
{
int tmp = (p1-list[])^(p2-list[]);
if(tmp > )return true;
else if(tmp == && dist2(p1,list[]) <= dist2(p2,list[]))
return true;
else return false;
}
void Graham(int n)
{
Point p0;
int k = ;
p0 = list[];
for(int i = ;i < n;i++)
if(p0.y > list[i].y || (p0.y == list[i].y && p0.x > list[i].x))
{
p0 = list[i];
k = i;
}
swap(list[],list[k]);
sort(list+,list+n,_cmp);
if(n == )
{
top = ;
Stack[] = ;
return;
}
if(n == )
{
top = ;
Stack[] = ;
Stack[] = ;
return;
}
Stack[] = ;
Stack[] = ;
top = ;
for(int i = ;i < n;i++)
{
while(top > && ((list[Stack[top-]]-list[Stack[top-]])^(list[i]-list[Stack[top-]])) <= )
top--;
Stack[top++] = i;
}
}
//旋转卡壳,求两点间距离平方的最大值
int rotating_calipers(Point p[],int n)
{
int ans = ;
Point v;
int cur = ;
for(int i = ;i < n;i++)
{
int j = (i+)%n;
int k = (j+)%n;
while(j != i && k != i)
{
ans = max(ans,abs((p[j]-p[i])^(p[k]-p[i])) );
while( ( (p[i]-p[j])^(p[(k+)%n]-p[k]) ) < )
k = (k+)%n;
j = (j+)%n;
}
}
return ans;
}
Point p[MAXN];
int main()
{
int n;
while(scanf("%d",&n) == )
{
if(n == -)break;
for(int i = ;i < n;i++)
list[i].input();
Graham(n);
for(int i = ;i < top;i++)
p[i] = list[Stack[i]];
int ans = rotating_calipers(p,top);
printf("%.2lf\n",ans/2.0);
}
return ;
}
 
 

POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)的更多相关文章

  1. hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)

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

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

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

  3. poj 2079 Triangle(旋转卡壳)

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

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

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

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

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

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

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

  7. 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 ...

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

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

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

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

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

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

随机推荐

  1. 【VI Script】你不知道的脚本编程

    前言 近期,小黑在写程序的时候,经常会遇到一些重复性的工作.尤其是在写到QMH(Queued Message Handler)程序时,经常需要创建UI界面上的一些控件引用,并且在程序中捆绑成簇使用. ...

  2. Freemarker中JS取Data-model的值的问题

    不能在表达式中使用js变量,比如: var key = 1; var value = "${stateMap[key]}"; 因为Freemarker是在服务器端进行解析的,此时j ...

  3. window.screen.height和window.screen.availHeight和document.body.clientHeight和document.documentElement.clientHeight

    说这几个属性前 我说一下我的设备 我的设备有两个,一个高度为1080的显示器,一个高度为800的电脑 第一种:window.screen.height 这个方法是获取用户电脑屏幕的高度,是不关浏览器或 ...

  4. Spring boot 集成hessian - LocalDateTime序列化和反序列化

    - 反序列化 import com.caucho.hessian.HessianException; import com.caucho.hessian.io.AbstractDeserializer ...

  5. Storm实战常见的问题

    该文档为实实在在的原创文档,转载请注明: http://blog.sina.com.cn/s/blog_8c243ea30101k0k1.html 类型 详细 备注 该文档是群里几个朋友在storm实 ...

  6. redis之(十三)redis的三种启动方式

    Part I. 直接启动 下载 官网下载 安装 tar zxvf redis-2.8.9.tar.gz cd redis-2.8.9 #直接make 编译 make #可使用root用户执行`make ...

  7. CentOS7.5字体美化

    背景知识 有衬线 (Serif) 无衬线 (Sans Serif) 和等宽 (Monospace) 字型 1 有衬线 (Serif) 字型是比较正式的字体,比划粗细不一,在笔划的边缘有装饰部分(我的理 ...

  8. 归并排序(MergeSort)

    原帖:http://blog.csdn.net/magicharvey/article/details/10192933 算法描述 归并排序(MergeSort)是采用分治法的一个非常典型的应用.通过 ...

  9. mysql 允许远程IP连接, 并查看所有用户的所有权限

    添加mysql用户 http://my.oschina.net/u/1179414/blog/202377 允许远程ip连接 GRANT select,insert,update,delete ON ...

  10. 【转载】FloatingActionButton源码解析

    原文地址:https://github.com/Rowandjj/my_awesome_blog/blob/master/fab_anlysis/README.md loatingActionButt ...