B. Maximal Area Quadrilateral
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.

Input

The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xiyi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.

Output

Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.

Sample test(s)
input
5
0 0
0 4
4 0
4 4
2 3
output
16.000000
Note

In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16.

题 意就是找4个点,求最大的四边形的面积,枚举对角线,我们可以求出上三角形的最大值,和下三角形的最大值,这样,我们就可以得出最大的四边形的面积,用叉积可以得出面积,还可以通过其正负,得出是上三角形,还是下三角形,这样,就可以得到了n^3的算法了!

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define M 350
#define eps 0
#define inf 10000000000
struct node {
double x,y;
}p[M];
double mul(int i,int j,int k){
return ((p[k].x-p[i].x)*(p[k].y-p[j].y)-(p[k].y-p[i].y)*(p[k].x-p[j].x))/2.0;
}
int main()
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
double lmax=-inf,rmax=-inf,amax=-inf;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i==j)
continue;
lmax=-inf,rmax=-inf;
for(k=0;k<n;k++){
if(i==k||j==k)
continue;
double temp=mul(i,j,k);
if(temp<eps){
lmax=max(lmax,-temp);
}
else {
rmax=max(rmax,temp);
}
}
amax=max(amax,lmax+rmax);
// printf("%.6f %.6ffdsf\n",amax,lmax+rmax);
}
}
printf("%.6f\n",amax);
}
return 0;
}

Codeforces Round #198 (Div. 2) B. Maximal Area Quadrilateral的更多相关文章

  1. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  2. Codeforces Round #198 (Div. 2)

    A.The Wall 题意:两个人粉刷墙壁,甲从粉刷标号为x,2x,3x...的小块乙粉刷标号为y,2y,3y...的小块问在某个区间内被重复粉刷的小块的个数. 分析:求出x和y的最小公倍数,然后做一 ...

  3. Codeforces Round #198 (Div. 1 + Div. 2)

    A. The Wall 求下gcd即可. B. Maximal Area Quadrilateral 枚举对角线,根据叉积判断顺.逆时针方向构成的最大面积. 由于点坐标绝对值不超过1000,用int比 ...

  4. Codeforces Round #198 (Div. 2) D. Bubble Sort Graph (转化为最长非降子序列)

    D. Bubble Sort Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. [置顶] Codeforces Round #198 (Div. 1)(A,B,C,D)

    http://codeforces.com/contest/341 赛后做的虚拟比赛,40分钟出了3题,RP爆发. A计数问题 我们可以对每对分析,分别对每对<a, b>(a走到b)进行统 ...

  6. Codeforces Round #506 (Div. 3) C. Maximal Intersection

    C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  7. Codeforces Round #198 (Div. 2) E. Iahub and Permutations —— 容斥原理

    题目链接:http://codeforces.com/contest/340/problem/E E. Iahub and Permutations time limit per test 1 sec ...

  8. Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest

    链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...

  9. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

随机推荐

  1. Ubuntu Git安装

    Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.通过使用git工具,我们可以实现团队间合作开发统一管理,可以从远程仓库中提取代码,也可以把代码上传到远程仓库,从而实现 ...

  2. 记录一次webbrowser无法加载 activex 遇到的问题

    关联配置: win7 x64 Adobe Reader XI activex 安装目录X84 笔者项目运行Any CPU 无论如何也加载不出PDF 刚开始还以为自己封装的控件XWebBrowser的问 ...

  3. java中如何获取系统时间

    需要引入的包有: import java.util.Date; 此为获取当前系统时间,合适为“1991-01-01” String now = "";    SimpleDateF ...

  4. iOS中的地图和定位

    文章摘自http://www.cnblogs.com/kenshincui/p/4125570.html#location  如有侵权,请联系删除. 概览 现在很多社交.电商.团购应用都引入了地图和定 ...

  5. parquet code demo

    http://www.programcreek.com/java-api-examples/index.php?source_dir=hiped2-master/src/main/java/hip/c ...

  6. ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'

    在我想把备份的数据库导入到本地数据的时候,发生这个错误,我使用的工具是dbForge Studio for MySQL ERROR 1044 (42000): Access denied for us ...

  7. 转移服务器,DEDE网站遇到no input file specified!

    公司新配置了服务器,需要从旧服务器上把原来的站点迁移到新服务器,迁移.NET网站没有遇到任何问题,但是在迁移过来一个用DEDE做的网站后,访问首页出现No Input File Specified,后 ...

  8. HTML+CSS笔记 CSS中级 一些小技巧

    水平居中 行内元素的水平居中 </a></li> <li><a href="#">2</a></li> &l ...

  9. JAVA GUI学习 - JInternalFrame浮动窗口:可拖拽窗口(依赖于父窗口)

    public class JInternalFrameKnow extends JInternalFrame { public JInternalFrameKnow() { this.setBound ...

  10. HDOJ 1427(dfs) 速算24点

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1427 思路分析: 题目要求判断是否存在一种运算组合使得4个数的计算结果为24,因为搜索的层次为3层,不 ...