题意:输入n个点(n<300),找出4个点组成4边形(凸四边),问最大面积多少?

题解:一个四边形是由两个三角形组成,直接枚举对角线,接下来枚举点,记录最小的和最大的叉积,就是距离这条线最远的两个点

#include <bits/stdc++.h>
#define ll long long
#define maxn 100100
#define Vector Point
using namespace std;
double eps = 1e-10;
int dcmp(double x) { return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1); }
struct Point {double x, y;Point(const Point& rhs): x(rhs.x), y(rhs.y) { } //拷贝构造函数Point(double x = 0.0, double y = 0.0): x(x), y(y) { }   //构造函数friend istream& operator >> (istream& in, Point& P) { return in >> P.x >> P.y; }friend ostream& operator << (ostream& out, const Point& P) { return out << P.x << ' ' << P.y; }friend Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }friend Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }friend Vector operator * (const Vector& A, const double& p) { return Vector(A.x*p, A.y*p); }friend Vector operator / (const Vector& A, const double& p) { return Vector(A.x/p, A.y/p); }friend bool operator == (const Point& A, const Point& B) { return dcmp(A.x-B.x) == 0 && dcmp(A.y-B.y) == 0; }friend bool operator < (const Point& A, const Point& B) { return A.x < B.x || (A.x == B.x && A.y < B.y); }
};
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }    //叉积
Point a[maxn];
int main(){int n;double ans = 0;cin>>n;for(int i=0;i<n;i++)cin>>a[i];for(int i=0;i<n;i++){for(int j=0;j<n;j++)if(i != j){double ma = -1e9, mi = 1e9;for(int k=0;k<n;k++)if(k!=i&&k!=j){double t = Cross(a[i]-a[j], a[k]-a[j]);ma = max(t, ma);mi = min(mi, t);}ans = max(ans, ma-mi);}}printf("%.9f\n", ans/2);return 0;
}

转载于:https://www.cnblogs.com/Noevon/p/8412579.html

Codeforces340B Maximal Area Quadrilateral相关推荐

  1. 【CodeForces - 340B 】Maximal Area Quadrilateral (计算几何,枚举,有坑)

    题干: Iahub has drawn a set of n points in the cartesian plane which he calls "special points&quo ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. czl蒻蒟的OI之路10、11、12

    好久没有发微博了表示自己也很绝望啊今天来个三连击 XJOI奋斗群蒻蒟群群赛11 RANK排名11 T1The Wall WA一次后AC 题意 分析过程 给出题解 T2Maximal Area Quad ...

  4. Janitor Troubles

    给定四个边,求所构成的四边形的最大面积用海伦公式 While working a night shift at the university as a janitor, you absentminde ...

  5. Dead Pixel CodeForces - 1315A(思维)

    Screen resolution of Polycarp's monitor is a×b pixels. Unfortunately, there is one dead pixel at his ...

  6. 19级算法训练赛第七场

    19级算法训练赛第七场 传送门:https://vjudge.net/contest/362412#problem/J A - 程序设计:合并数字 蒜头君得到了 n 个数,他想对这些数进行下面这样的操 ...

  7. 全国各省市区数据sql格式(utf8)

    一.省 DROP TABLE IF EXISTS `provinces`; CREATE TABLE `provinces` ( `id` int(11) NOT NULL auto_incremen ...

  8. LeetCode 221. Maximal Square----动态规划--谷歌面试算法题--Python解法

    题目地址:Maximal Square - LeetCode Given a 2D binary matrix filled with 0's and 1's, find the largest sq ...

  9. [LeetCode]Maximal Rectangle

    Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...

最新文章

  1. 7-17 爬动的蠕虫 (C语言)
  2. VR如何巧妙填补传统数据视觉化的漏洞
  3. 存储格式之大端小端详解
  4. 关于perl中变量内插问题的讨论
  5. php 设置断点,PHP xdebug安装配置(支持断点调试)
  6. break 与continue的区别
  7. web api开启错误提示_当HTTP状态代码不足时:处理Web API错误报告
  8. uva 10954——Add All
  9. C++ template —— 动多态与静多态(六)
  10. 【十五分钟Talkshow】如何善用你的.NET开发环境
  11. 关于Excel的查询,可以通过格式查询(比如查找指定颜色的单元格)。
  12. 【Java集合系列一】ArrayList解析
  13. Jquery和JS获取ul中li标签
  14. Linux下的Vivado安装——以Ubuntu为例
  15. 用matlab做bp神经网络预测,matlab神经网络怎么预测
  16. @inherited 注解详解
  17. Java后端社招面试经历,不愧是大佬
  18. Oracle 数据库中的 时间 时区
  19. 【操作系统】第三章:内存管理
  20. 网络工程师——Super VLAN

热门文章

  1. 不用去验血,一查就能知道自己缺啥,一定要收好
  2. 万物联网IoE与物联网IOT有何差别?
  3. js获取页面传来参数的方法
  4. 【Android XMPP】 学习资料收集贴(持续更新)
  5. wait(3) - Linux man page
  6. 怎么搞一个ORM出来用用呢???迷茫中
  7. 计算机的各种英语名称,计算机设备名称英语词汇
  8. 疲劳驾驶样本集_欧洲要求,2022年开始新车必须配备DMS(防疲劳预警)系统
  9. 阿里云mysql本地可以连接数据库_本地电脑连接阿里云服务器上搭建的MySQL数据库...
  10. Vue之表单数据收集