Codeforces 340B - Maximal Area Quadrilateral (计算几何)
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 (计算几何)的更多相关文章
- codeforces 340B Maximal Area Quadrilateral(叉积)
事实再一次证明:本小菜在计算几何上就是个渣= = 题意:平面上n个点(n<=300),问任意四个点组成的四边形(保证四条边不相交)的最大面积是多少. 分析: 1.第一思路是枚举四个点,以O(n4 ...
- Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积
Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...
- 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 ...
- 【codeforces 340B】Maximal Area Quadrilateral
[题目链接]:http://codeforces.com/problemset/problem/340/B [题意] 给你n个点,让你在这里面找4个点构成一个四边形; 求出最大四边形的面积; [题解] ...
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
- Codeforces 803C. Maximal GCD 二分
C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...
- 2018.07.04 POJ 1265 Area(计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- CodeForces C. Maximal Intersection
http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...
随机推荐
- 4、jQuery面向对象之简单的插件开发
1.alert例子 (function($){ $.alert = function(msg){ window.alert(msg); } $.fn.alert = function(msg){ wi ...
- windbg bp condition
0:000> bp 0012f2fc "j @ecx == 0 '';'gc'" 0:000> g j代表judgement,与c++中的condition?A:B类似 ...
- MyBatis原理,Spring、SpringBoot整合MyBatis
1. MyBatis概述 MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可 ...
- 常用内置模块(一)——time、os、sys、random、shutil、pickle、json
常用内置模块 一.time模块 在python中,时间分为3种 1.时间戳: timestamp,从1970年1月1日到现在的秒数, 主要用于计算两个时间的差 2.localtime ...
- jmeter 响应超时时间设置 压力增大,不能正常退出全部线程
当压力增大会出现connect timeout error 压力增大,不能正常退出全部线程: 解决办法:http request default--advance--timeouts 如填写1,表示大 ...
- python面试题之下面这些是什么意思:@classmethod, @staticmethod, @property?
回答背景知识 这些都是装饰器(decorator).装饰器是一种特殊的函数,要么接受函数作为输入参数,并返回一个函数,要么接受一个类作为输入参数,并返回一个类. @标记是语法糖(syntactic s ...
- 详解 Flexible Box 中的 flex 属性
导读: 弹性盒子是 CSS3 的一种布局模式,一种当页面需要适应不同的屏幕大小以及设备类型时确保元素拥有适当的行为的布局方式.其中 flex 属性用于指定弹性子元素如何分配空间. flex 属性的值 ...
- 使用python+ffmpeg批量转换格式
需求: 给定一个文件夹路径,遍历该文件夹内的所有文件以及子文件夹内的文件,当所有后缀名为wav格式的文件转换为ogg格式的文件. import os # 获取目录下的所有文件列表 import fn ...
- EXCEL数据计算不准确的问题
今天,某部门的excel的数值计算,总是出现错误.如下图 ,我们的46那一栏是有前面8*6得出来的,但是结果却显示46,明明应该是48才对,然后再往上追,8是有前面的337-329得出来的,337是有 ...
- 笔记68 Redis数据库
一.Redis简介 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Redis是一个开源的使用ANSI ...