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

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

【思路】

  凸包+旋转卡壳

  旋转卡壳:先确定两个点,叉积寻找最大的第三点,然后改变第二个点继续。

  Quote:求点集中的最大三角形面积,O(n) 的旋转卡壳,先凸包,然后选取开头三个点 p,q,r 开始旋转,注意 r 不超过第一个点,q 不超过 r,p 不超过 q 。每次做三次推进,先推进 r,使 pq 不动面积最大,然后推进 q,再推进 p,如果三次都没有推进过,r 推进一格。每次推进完一个点都更新一下面积最大值。

【代码】

 #include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#define FOR(a,b,c) for(int a=(b);a<=(c);a++)
using namespace std; struct Pt {
int x,y;
Pt(int x=,int y=):x(x),y(y) {};
};
typedef Pt vec; vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); }
bool operator < (const Pt& a,const Pt& b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
}
bool operator == (const Pt& a,const Pt& b) {
return a.x==b.x && a.y==b.y;
}
int cross(vec A,vec B) { return A.x*B.y-A.y*B.x; }
int dist(Pt A,Pt B) {
return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
}
vector<Pt> ConvexHull(vector<Pt> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size() , m=;
vector<Pt> ch(n+);
for(int i=;i<n;i++) {
while(m> && 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 && cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
ch.resize(m); return ch;
} int n;
vector<Pt> p,ch; int RC() {
int n=ch.size();
int ans= , cur= , j,k;
Pt v;
FOR(i,,n-) {
j=(i+)%n , k=(j+)%n;
while(j!=i && k!=i) {
ans=max(ans,abs(cross(ch[j]-ch[i],ch[k]-ch[i])));
while(cross(ch[i]-ch[j],ch[(k+)%n]-ch[k])<) k=(k+)%n;
j=(j+)%n;
}
}
return ans;
} int main() {
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
while(scanf("%d",&n)== && n!=-) {
p.clear() , ch.clear();
int x,y;
FOR(i,,n) {
scanf("%d%d",&x,&y);
p.push_back(Pt(x,y));
}
ch=ConvexHull(p);
printf("%.2lf\n",RC()/2.0);
}
return ;
}

poj 2079 Triangle(旋转卡壳)的更多相关文章

  1. POJ 2079 Triangle [旋转卡壳]

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

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

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

  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. Oracle的安装

    本人所使用的数据库平台为Oracle 11g 1.下载Oracle Oracle官网即可下载Oracle平台.不过网上资源丰富,大家也可在百度云网盘找到合适的版本. 附上本人网盘里存储的各个Oracl ...

  2. IOS 学习笔记 2015-03-24 OC-API-常用结构体

    一 标题 常用结构体 二 API 1 NSRange 表示一个范围 A 实例化 NSRange rg={3,5};//第一参数是起始位置第二个参数是长度 B 实例化 NSRange rg2=NSMak ...

  3. Spring in action笔记

    耦合的两面性     一方面代码耦合难以测试,会出现打地鼠式的bug特性(修复一个bug,引发另一个bug) 另一方面耦合又是必须的,不同的类必须要进行适当的交互,才能实现功能. bean的四种装配方 ...

  4. JavaScript之Chart.js图例(legend)

    #html <div id="chart_line_legend" class="chart-legend"></div> <ca ...

  5. pdo如何防止 sql注入

    我们使用传统的 mysql_connect .mysql_query方法来连接查询数据库时,如果过滤不严,就有SQL注入风险,导致网站被攻击,失去控制.虽然可以用 mysql_real_escape_ ...

  6. Ubuntu 12.04如何从登录界面登录root

    root登录,可以使我们拥有管理系统最高的权限,但是随之带来的也是,系统的安全得不到足够的保障.Ubuntu官方资料说不推荐我们以root方式登录到系统中,但是如果我们真想这么做,也是可以的. 不同版 ...

  7. html+css篇

    一,html语义话标签 http://www.html5jscss.com/html5-semantics-section.html

  8. 关于MATLAB中的tic toc的问题

    关于MATLAB中的tic toc的问题 其一) MATLAB实际单位时间计时函数的具体应用,在编写程序时,经常需要获知代码的执行实际时间,这就需要在程序中用到计时函数,matlab中提供了以下三种方 ...

  9. IronPython脚本调用C#dll示例

    上篇Python脚本调用C#代码数据交互示例(hello world)介绍了与C#紧密结合的示例,这里还将提供一个与C#结合更紧密的示例,直接调用C#编写的DLL.      我们还是沿用了上篇文章的 ...

  10. IIS 500 – 内部服务器错误解决方案

    最近装了测试机windows2008使用IIS7.5各种不习惯呀,各种问题,唉.. 今天又遇到了“500 – 内部服务器错误. 您查找的资源存在问题,因而无法显示.”的问题,网上查找了一下,找到解决办 ...