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. 两个textarea 同时变化高度

    <html><head><script type="text/javascript" src="/jquery/jquery.js" ...

  2. SqlServer 2015修改表时出现“save changes is not permitted…”的解决方法

    使用SqlServer 2015的过程中,会出现如下情况: 在修改完表字段名或是类型后点击保存时会弹出一个对话框,且无法保存已做的修改.对话框内容大致如下: Saving changes is not ...

  3. SQL函数经常用到的mark一下

    在项目开发过程中存储过程会用到很多SQL函数,经常用到的mark一下 1.经常用到的mark 一下 经常需要把id字符以','分隔传入存储过程然后SQL语句用in去搜索但是经常是这样的情况id 经常是 ...

  4. Unity UGUI在鼠标位置不同时 图片浮动效果

    /// <summary> /// 在鼠标位置不同时 图片浮动效果 /// </summary> public class TiltWindow : MonoBehaviour ...

  5. 笔记 postgresql oid同步

    以前学习postgresql的笔记 create table 消耗 OID 如create table my_test_table, 他本身会消耗一个 会在pg_type中插入两条记录_my_test ...

  6. JavaSE学习总结第26天_网络编程

      26.01  网络编程概述 网络编程:就是用来实现网络互连的不同计算机上运行的程序间可以进行数据交换. 26.02  网络模型概述和图解 计算机网络之间以何种规则进行通信,就是网络模型研究问题. ...

  7. malloc/free和new/delete的区别汇总

    一.基本概念 malloc/free 1.函数原型及说明: void* malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针.如果分配失败,则返回 ...

  8. 把复选框变成单选框(prop,attr的区别)

    如果项目中需要统一样式的话,有可能会遇到把复选框变成单选框的需求. 下面是用jquery的简单实现 $(function(){ $("input[type='checkbox']" ...

  9. Mysql开启远程

    改表法: x:\>mysql -u root -pvmware mysql> use mysql;mysql> update User set Host = ‘%’ where Us ...

  10. Linux C 简易聊天室

    Linux下实现聊天室 介绍:程序在CentOS下,采用C语言实现,结构为Client/Server结构; 服务端程序通过共享存储区存储聊天数据,并发送给每个连接的客户端: 服务端程序和客户端程序都是 ...