Problem Description

老师在计算几何这门课上给Eddy布置了一道题目,题目是这样的:给定二维的平面上n个不同的点,要求在这些点里寻找三个点,使他们构成的三角形拥有的面积最大。
Eddy对这道题目百思不得其解,想不通用什么方法来解决,因此他找到了聪明的你,请你帮他解决这个题目。

Input

输入数据包含多组测试用例,每个测试用例的第一行包含一个整数n,表示一共有n个互不相同的点,接下来的n行每行包含2个整数xi,yi,表示平面上第i个点的x与y坐标。你可以认为:3 <= n <= 50000 而且 -10000 <= xi, yi <= 10000.

Output

对于每一组测试数据,请输出构成的最大的三角形的面积,结果保留两位小数。
每组输出占一行。

Sample Input

3
3 4
2 6
3 7
6
2 6
3 9
2 0
8 0
6 6
7 7

Sample Output

1.50
27.00

Author

Eddy

Recommend

lcy

思路:

最大三角形的三个点一定在点的凸包上,求出凸包之后,直接暴力枚举点即可

代码:

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 55000;
const int INF = 0x3f3f3f3f;
const int eps = 1e-8;
int sgn(double x)//判断浮点数x的符号,0返回0,正数返回1,负数返回-1
{
if (fabs(x) < eps)return 0;
if (x < 0)return -1;
else return 1;
}
struct Point
{
int x, y;
Point() {}
Point(int _x, int _y)
{
x = _x; y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y);
} double operator ^(const Point &b)const //叉积
{
return x * b.y - y * b.x;
} double operator *(const Point &b)const //点积
{
return x * b.x + y * b.y;
}
bool operator ==(const Point &b)const
{
return (x == b.x) && (y == b.y);
}
bool operator !=(const Point&b)const
{
return (x != b.x) || (y != b.y);
}
void input() { //点的输入
scanf("%d%d", &x, &y);
}
};
struct Line {
Point s, e;
Line() {}
Line(Point _s, Point _e) {
s = _s; e = _e;
}
}; double dist(Point& a, Point& b) //*两点间距离
{
return sqrt((a - b) * (a - b));
}
Point zero;
int k;
bool cmp(Point& a, Point &b)
{
double tmp = (a - zero) ^ (b - zero);
if (sgn(tmp) > 0) {
return 1;
}
if (sgn(tmp) == 0 && sgn(dist(a, zero) - dist(b, zero)) <= 0)
return 1;
return 0;
}
int n;
Point a[MAXN];
int l[MAXN];
int cou = 0;
void Gram()
{
cou = 0;
swap(a[0], a[k]);
sort(a + 1, a + n, cmp);
if (n == 1) {
l[cou++] = 0;
return;
}
if (n == 2) {
l[cou++] = 0;
l[cou++] = 1;
return;
}
l[cou++] = 0;
l[cou++] = 1;
for (int i = 2; i < n; i++) {
while (sgn((a[i] - a[l[cou - 2]]) ^ (a[l[cou - 1]] - a[l[cou - 2]])) != -1) {
cou--;
}
l[cou++] = i;
}
}
int main()
{
//freopen("data.in", "r", stdin);
while (~scanf("%d", &n)) {
zero.x = zero.y = INF;
for (int i = 0; i < n; i++) {
a[i].input();
if (a[i].y < zero.y) {
zero.x = a[i].x;
zero.y = a[i].y;
k = i;
}
else if (a[i].y == zero.y) {
if (a[i].x < zero.x) {
zero.x = a[i].x;
zero.y = a[i].y;
k = i;
}
}
}
Gram();
double res = -3;
for (int i = 0; i < cou; i++) {
for (int j = 0; j < cou; j++) {
for (int k = 0; k < cou; k++) {
double tmp = fabs((a[l[i]] - a[l[j]]) ^ (a[l[k]] - a[l[j]]));
if (tmp > res) {
res = tmp;
}
}
}
}
res = res / 2 ;
printf("%.2lf\n", res);
}
}

HDU2202--最大三角形(凸包,枚举)的更多相关文章

  1. poj1873 The Fortified Forest 凸包+枚举 水题

    /* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...

  2. poj 1873 凸包+枚举

    The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1 ...

  3. hdu 4709:Herding(叉积求三角形面积+枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. hdu 2202 最大三角形 (凸包)

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. 简单几何(凸包+枚举) POJ 1873 The Fortified Forest

    题目传送门 题意:砍掉一些树,用它们做成篱笆把剩余的树围起来,问最小价值 分析:数据量不大,考虑状态压缩暴力枚举,求凸包以及计算凸包长度.虽说是水题,毕竟是final,自己状压的最大情况写错了,而且忘 ...

  6. UVa1453或La4728 凸包+枚举(或旋转卡壳)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. POJ 1873 The Fortified Forest [凸包 枚举]

    The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6400   Accepted: 1 ...

  8. BZOJ 1201 [HNOI2005]数三角形:枚举 + 前缀和

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1201 题意: 有一个边长为n的正三角形网格,去掉其中一些线段,问你在这幅图中有多少个三角形 ...

  9. (hdu step 7.1.6)最大三角形(凸包的应用——在n个点中找到3个点,它们所形成的三角形面积最大)

    题目: 最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  10. hdu 最大三角形(凸包+旋转卡壳)

    老师在计算几何这门课上给Eddy布置了一道题目,题目是这样的:给定二维的平面上n个不同的点,要求在这些点里寻找三个点,使他们构成的三角形拥有的面积最大.Eddy对这道题目百思不得其解,想不通用什么方法 ...

随机推荐

  1. 【Loadrunner】初学Loadrunner——场景设计

    在使用Loadrunner的时候,常常需要使用到场景设计.但是怎么设计一个满意的场景?如何开展? 首先可以点击tools > Create Controller Scenario > OK ...

  2. ajax写法

    $.ajax({ type:'post', url:'<%=path%>/login', cache:false, dataType:'json', success:function(da ...

  3. 得分(Score, ACM/ICPC Seoul 2005,UVa 1585)

    #include<cstdio>#include<cstdlib>#include<cstring>int main(){ char s[80];//输入OOXXO ...

  4. 【Python之路】第六篇--Python基础之模块

    模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...

  5. lucene 自定义评分

    摘自:http://blog.csdn.net/seven_zhao/article/details/42708953 1.基于FunctionQuery,(1)创建类并继承ValueSource:( ...

  6. SQLServer性能优化

    http://www.cnblogs.com/studyzy/archive/2008/11/24/1339772.html

  7. redis34--string 操作

    String类型操作 1.set key value 设置key对应的值为string类型的value  2.mset key1 value1 - keyN valueN 一次设置多个key的值 3. ...

  8. ZOJ 2710 Two Pipelines

    计算几何+贪心 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm&g ...

  9. 如何在sublime中使用sass

    搞了好久,终于把sass搞定了. 最开始,我是想使用koala来实现对sass的实时编译的,但是每当我保存的时候,总是弹出erro错误,即无法编译生成css文件,百度了半天,问了好久,这个问题还是没能 ...

  10. children

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> </head> ...