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. SDK无法更新

    http://jingyan.baidu.com/article/da1091fbd232fe027949d653.html

  2. Unity 通过NGUI 完成单摄像机 制作地图

    本次思想主要是通过 Ngui的Scroll View 主要是UIPanel的Clipping属性的Alipha Clip 调节窗口大小,遮蔽地图试地图实现在屏幕的部分显示.此方法的好处是不用担心sha ...

  3. slots

    class Student(object): pass s = Student() s.name = 'Michael' print(s.name) def set_age(self, age): s ...

  4. BZOJ 1449: [JSOI2009]球队收益( 最小费用最大流)

    先考虑假如全部输了的收益. 再考虑每场比赛球队赢了所得收益的增加量,用这个来建图.. --------------------------------------------------------- ...

  5. Lucence.net索引技术 二

    一. Lucene索引创建和优化 [版本2.9.0以上] Lucene索引的创建首先需要取得几个必须的对象: 1.分词器//可以采用其他的中文分词器 StandardAnalyzer analyzer ...

  6. apache 配置文件管理

    1. Apache配置系统 从整体来看apache的配置系统包括三个部分: (1) 配置文件:比如 httpd.conf   .htaccess (2) 配置指令:在配置文件 httpd.conf  ...

  7. C part 1 -- 指令篇

    Windows系统的cmd(command命令行工具): Shutdown -s -t 600:表示600秒后自动关机 Shutdown -a :可取消定时关机 Shutdown -r -t 600: ...

  8. python自学笔记(八)python语句

    一.print语句 1.1 基本输出,自动分行 1.2 print的逗号,可以衔接前面的内容而不换行,在一行内 1.3 >>重定向,输出到文件 print >> 文件名,&qu ...

  9. HDU 1983 Kaitou Kid - The Phantom Thief (2)

    神题,搜索太差,来自网络的题解与程序 思路: 封锁出口或者入口周围的格子. 最多需要4个封锁点. 所以我们可以采取这样的策略: 1.寻找一条盗贼的可行路线,如果没有,返回0. 2.计算封锁出口和入口四 ...

  10. CSS3属性之border-radius

    一.语法: 代码如下: border-radius : none |  <length>{1,4} [/  <length>{1,4} ]? 二.取值: <length& ...