Codeforces Round #198 (Div. 2)

题目链接:Maximal Area Quadrilateral

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 \le n \le 300)\). Each of the next \(n\) lines contains two integers: \(x_i, y_i ( - 1000 \le xi, yi \le 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}\).

Examples

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\cdot 4 = 16\).

Solution

题意

给定 \(n\) 个点的坐标,选择其中 \(4\) 个点构成四边形,求最大四边形面积。

题解

四边形的面积等于两个三角形面积的和。枚举四边形的对角线,以及左右两边的点,选择两个面积最大的三角形,更新 \(ans\)。

三重循环枚举,时间复杂度 \(O(n^3)\)。

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const db eps = 1e-10;
const db pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 300 + 5; inline int dcmp(db x) {
if(fabs(x) < eps) return 0;
return x > 0? 1: -1;
} class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
void input() {
scanf("%lf%lf", &x, &y);
}
bool operator<(const Point &a) const {
return (!dcmp(x - a.x))? dcmp(y - a.y) < 0: x < a.x;
}
bool operator==(const Point &a) const {
return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0;
}
db dis2(const Point a) {
return pow(x - a.x, 2) + pow(y - a.y, 2);
}
db dis(const Point a) {
return sqrt(dis2(a));
} db dis2() {
return x * x + y * y;
}
db dis() {
return sqrt(dis2());
}
Point operator+(const Point a) {
return Point(x + a.x, y + a.y);
}
Point operator-(const Point a) {
return Point(x - a.x, y - a.y);
}
Point operator*(double p) {
return Point(x * p, y * p);
}
Point operator/(double p) {
return Point(x / p, y / p);
}
db dot(const Point a) {
return x * a.x + y * a.y;
}
db cross(const Point a) {
return x * a.y - y * a.x;
}
};
typedef Point Vector; vector<Point> p; map<pair<int, int>, int> mp; int main() {
double ans = 0;
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
Point tmp;
tmp.input();
p.push_back(tmp);
}
sort(p.begin(), p.end());
for(int i = 0; i < p.size(); ++i) {
for(int j = i + 1; j < p.size(); ++j) {
if(!mp[{i, j}]) {
mp[{i, j}] = 1;
double s1 = 0, s2 = 0;
for(int k = 0; k < p.size(); ++k) {
if(k == i || k == j) continue;
if(dcmp((p[j] - p[i]).cross(p[k] - p[i])) > 0) {
s1 = max(s1, fabs((p[j] - p[i]).cross(p[k] - p[i])) * 0.5);
} else {
s2 = max(s2, fabs((p[j] - p[i]).cross(p[k] - p[i])) * 0.5);
}
}
if(dcmp(s1) == 0 || dcmp(s2) == 0) continue;
ans = max(ans, s1 + s2);
}
}
}
printf("%.10lf\n", ans);
return 0;
}

Codeforces 340B - Maximal Area Quadrilateral (计算几何)的更多相关文章

  1. codeforces 340B Maximal Area Quadrilateral(叉积)

    事实再一次证明:本小菜在计算几何上就是个渣= = 题意:平面上n个点(n<=300),问任意四个点组成的四边形(保证四条边不相交)的最大面积是多少. 分析: 1.第一思路是枚举四个点,以O(n4 ...

  2. Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积

    Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...

  3. Codeforces Round #198 (Div. 2) B. Maximal Area Quadrilateral

    B. Maximal Area Quadrilateral time limit per test 1 second memory limit per test 256 megabytes input ...

  4. 【codeforces 340B】Maximal Area Quadrilateral

    [题目链接]:http://codeforces.com/problemset/problem/340/B [题意] 给你n个点,让你在这里面找4个点构成一个四边形; 求出最大四边形的面积; [题解] ...

  5. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

  6. Codeforces 803C. Maximal GCD 二分

    C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...

  7. 2018.07.04 POJ 1265 Area(计算几何)

    Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...

  8. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. CodeForces C. Maximal Intersection

    http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...

随机推荐

  1. MySQL允许远程登录配置

    1.查看user表mysql> use mysqlReading table information for completion of table and column namesYou ca ...

  2. VEX IR语言语法

    /*---------------------------------------------------------------*//*--- High-level IR description - ...

  3. 2019牛客多校第⑨场E All men are brothers(并查集+组合数学)

    原题:https://ac.nowcoder.com/acm/contest/889/E 思路: 做并查集,维护每个集合大小,初始化操作前的总方案数,每次合并两个集合时减少的数量=合并的两个集合大小相 ...

  4. 【IO流】java中文件路径(相对路径、绝对路径)相关类及方法

    原文链接:https://blog.csdn.net/Activity_Time/article/details/98034409 1. URL 菜鸟教程:Java URL处理 通常推荐对http等协 ...

  5. lucene简单使用

    lucene7以上最低要求jdk1.8 lucene下载地址: http://archive.apache.org/dist/lucene/java/ <dependency> <g ...

  6. python 模拟双色球输出

    编写Python函数:完成一个双色球彩票的模拟生成过程, 其中前六个为红色球,数字范围1-33,不可重复.最后一个为蓝色球 1-16. import random #red_nums是采集红色球的数字 ...

  7. ansible了解

    基础知识: ansible简介 ansible 是个什么东西呢?基于 Python paramiko 开发,分布式,无需客户端,轻量级,配置语法使用 YMAL 及 Jinja2模板语言,更强的远程命令 ...

  8. CSS和jQuery分别实现图片无缝滚动效果

    一.效果图 二.使用CSS实现 <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g ...

  9. ionic3 图片(轮播)预览 ionic-gallary-modal组件使用方法

    一.效果展示 使用方法: 1.npm安装ionic-gallary-modal扩展模块 npm install ionic-gallery-modal --save 2.在app.module.ts根 ...

  10. spring3+structs2整合hibernate4时报org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void sy.dao.impl.UserDaoImpl.setSessionFactory(org.hibernate.SessionFactory);

    今天在spring3+structs2整合hibernate4时报如下错误,一直找不到原因: org.springframework.beans.factory.BeanCreationExcepti ...