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 ...
随机推荐
- 搭建Linux C语言开发环境
1.操作系统 Windows操作系统:windows 7 and windows 10 2.开发工具和编译工具 开发工具:notpad++ 和 vim 编译工具:Cygwin64 Terminal 3 ...
- 用FastDFS一步步搭建图片服务器(单机版)
一.FastDFS介绍 FastDFS开源地址:https://github.com/happyfish100 参考:分布式文件系统FastDFS设计原理 参考:FastDFS分布式文件系统 1.简介 ...
- vue-cli3.0打包完自动压缩zip
打包是我们常见的操作 一般打包完还需要压缩丢到服务器解压 首先 我们需要一个 filemanager-webpack-plugin npm i filemanager-webpack-plugin - ...
- 比较全面的CSS hack方式一览
转载请注明来自CSDN freshlover的博客专栏<史上最全CSS Hack方式一览> 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某 ...
- 菩提圣心诀---zabbix自定义key监控oracle连接状态(python脚本)
目的:此次实验目的是为了zabbix服务端能够实时监控某服务器上oracle实例能否正常连接 环境:1.zabbix_server 2.zabbix_agent(含有oracle) 主要知识点: 1. ...
- linux系统:go build报错import cycle not allowed
go build 困扰我多时的 go 编译报错:循环导入,代码肯定是没问题的,网上查说重新安装go 我觉得也不是太好的办法 import cycle not allowed package day01 ...
- Cas 4.2.7 OAuth+Rest 实现SSO
关于Cas的认证原理.Rest的使用请参考前面的文章.本文重点阐述使用Rest接口登陆系统和其他单点登录系统打通遇到的问题,及解决问题的思路和过程. 一: 遇到的问题 使用Res ...
- Javascript高级程序设计--读书笔记之Array类型
1.数组的lenght属性 数组的lenght属性很有特点---他不是只读的,可以同过修改这个属性来向数组的末尾添值加或删除值, 删除值 var color = ["red", & ...
- hbuilder模拟器端口
模拟器 | 端口 夜神安卓模拟器夜神安卓模拟器 62001 逍遥安卓模拟器逍遥安卓模拟器 21503 BlueStacks(蓝叠安卓模拟器)BlueStacks(蓝叠安卓模拟器) ...
- 【LeetCode】水题(刚开始重新刷题找感觉用的)
[9] Palindrome Number [Easy] 给一个数字,用不转化成字符串的方式判断它是否是回文. 先求数字长度,然后把数字的后半段做翻转(就是不断地取模,除10这种方式),然后判断前后半 ...