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

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

题意:平面上给定若干点,求由这些点所组成的三角形中面积最大的三角形。
思路:首先肯定要求出这些店的凸包,三角形的三个定点一定在凸包上。之后考虑如何确定出面积最大的三角形。我们首先固定凸包上其中两个点1,2作为三角形的两个顶点,顶点3则不断的在凸包上运动,一开始运动的时候三角形的面积会逐渐变大,直到运动到某一点使三角形面积达到最大值,之后若顶点3继续运动则三角形面积又开始不断减小,
这时3停止运动,顶点1,2换一个组合,重复上述算法求面积最大值。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
#define EPS 1e-10
#define INF 0x3f3f3f3f
const int N_MAX = +; struct P {
int x, y;
P(){}
P(int x,int y):x(x),y(y) {}
P operator +(P p) {
return P(x+ p.x,y+ p.y);
}
P operator -(P p) {
return P(x -p.x, y -p.y);
}
P operator *(P p) {
return P(x*p.x, y*p.y);
}
bool operator <(const P& p)const {
if (x != p.x)return x < p.x;
else return y < p.y;
}
int dot(P p) {
return x*p.x+y*p.y;
}
int det(P p) {
return x*p.y-y*p.x;
} };
bool cmp_x(const P&p,const P&q) {
if (p.x != q.x)
return p.x < q.x;
return p.y < q.y;
} struct Segment {
P p1, p2;
Segment(P p1=P(),P p2=P()):p1(p1),p2(p2) {}
};
typedef Segment Line;
typedef vector<P>Polygon; inline double cross(P A, P B, P C)
{
return (B - A).det(C - A);
} int triangle_S(Segment s,P p) {
return (s.p2 - s.p1).det(p - s.p1);
} Polygon convex_hull(P * ps,int n) {
sort(ps,ps+n);
int k = ;
Polygon qs(n * );
for (int i = ; i < n;i++) {
while (k > && (qs[k - ] - qs[k - ]).det(ps[i] - qs[k - ]) <= ) k--;
qs[k++] = ps[i];
}
for (int i = n - , t = k; i >= ;i--) {
while (k > t && (qs[k - ] - qs[k - ]).det(ps[i] - qs[k - ]) <= )k--;
qs[k++]=ps[i];
}
qs.resize(k-);
return qs;
} P po[N_MAX];
int N; vector<P> judge_clockwise(vector<P>p) {
for (int i = ; i < p.size()-;i++) {
//double tmp = (p[i + 1] - p[i]).det(p[i + 2] - p[i + 1]);
double tmp = cross(p[i], p[i + ], p[i + ]);
if (tmp > EPS)return p;
else if (tmp < -EPS) {
reverse(p.begin(), p.end());
return p;
}
}
return p;
} void solve(Polygon po,int n) {
int nnext;
int res = ;
for (int offset = ; offset < (n + ) / ;offset++) {//offset为三角形底边两个顶点的跨度
nnext = (offset + ) % n;
for (int i = ; i < n; i++) {
int next = (i + offset) % n;
Segment s = Segment(po[i], po[next]);
int S = triangle_S(s, po[nnext]);
int S_MAX = S;
for (++nnext; nnext != next&&nnext != i;nnext++) {
if (nnext == n)nnext = ;
int S = triangle_S(s,po[nnext]);
res = max(res, S_MAX);
if (S<= S_MAX)break;
S_MAX = S;
}
if (nnext > )nnext--;//!!!!!!!!!!!!!!!!!!!
else nnext = n - ;
}
}
printf("%d.%s\n", res/ , res % == ? "" : "");
} int main() { while (scanf("%d",&N)&&N!=-) {
for (int i = ; i < N;i++) {
scanf("%d%d",&po[i].x,&po[i].y);
}
Polygon Po = convex_hull(po, N);
solve(Po,Po.size());
}
return ;
}

poj 2079 Triangle的更多相关文章

  1. ●POJ 2079 Triangle

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

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

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

  3. poj 2079 Triangle(旋转卡壳)

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

  4. POJ 2079 Triangle [旋转卡壳]

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. TabControl重写,添加关闭按钮

    class userTabControl : TabControl { const int CLOSE_SIZE = 15; protected override void OnInvalidated ...

  2. 头文件string与string.h的区别

    在C++中,#include<iostream>与#include<iostream.h>的区别,前者要使用更新的编译器(其实大部分编译器多比较前卫了,出了有些搞嵌入式的用变态 ...

  3. C++ 学习笔记(二) const的加强

    const 含义为只读.如果在程序中显式改变const变量那么编译会报错. C语言的const: 在C语言中const 变量是放在内存中,如果使用指针可以间接改变const变量.所以在C语言中cons ...

  4. Golang 简单web测试

    // mhoso project main.go package main import ( "log" "net/http" "./controll ...

  5. 04Windows中的字符类型

    1. Windows 中常用的数据类型定义 //WinNt.h中定义 typedef unsigned short wchar_t; //A 16-bit character typedef char ...

  6. Ubuntu下kaldi安装

    该文章为博主原创,如若转载请注明出处:https://www.cnblogs.com/fengleixue/p/9482202.html 因公司业务需要需使用kaldi语音识别工具,现将kaldi环境 ...

  7. 再生龙备份还原linux系统

    相关下载: Clonezilla再生龙:http://sourceforge.net/projects/clonezilla/files/clonezilla_live_stable/ tuxboot ...

  8. 如何用纯 CSS 创作一个过山车 loader

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/KBxYZg/ 可交互视频 此视频是 ...

  9. matplotlib学习记录 三

    # 绘制自己和朋友在各个年龄的女友数量的折线图 from matplotlib import pyplot as plt # 让matplotlib能够显示中文 plt.rcParams['font. ...

  10. Altium Designer入门学习笔记2:使用原创客3D元件库

    请自行淘宝购买: 元件库列表(2018年11月27日): 问题一:在项目库或已安装的库中找不到? 将"原创客"提供的文件全部添加到libraries中!"原创客" ...