【CodeForces - 340B 】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 ≤ 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.

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·4 = 16.

题目大意:

   给你n个点,让你从这些点里面寻找4个点,使得四边形的面积最大。当然题目说了没有三个点在一条线上,没有重合的点。

解题报告:

   这题看起来不难啊,,把四个点拆成两个三角形然后枚举2+1+1,三重循环就搞定了,,但是这题还是很坑的啊,,WA23的同党肯定不少吧,,看这个简单的B题当时cf比赛的时候比D过题的人都少(不过也可能因为这场的D确实简单,看懂了就是个模板题)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
const double eps = 1e-8;
int sgn(double x) {if(fabs(x) < eps)return 0;if(x < 0) return -1;return 1;
}
struct Point {double x,y;int id;Point() {}Point(double x,double y):x(x),y(y) {}Point operator -(const Point &b)const {return Point(x - b.x,y - b.y);}double operator ^(const Point &b)const {return x*b.y - y*b.x;}double operator *(const Point &b)const {return x*b.x + y*b.y;}
} p[1005];
double ans,ans1,ans2;
int main()
{int n;cin>>n;for(int i = 1; i<=n; i++) scanf("%lf%lf",&p[i].x,&p[i].y),p[i].id = i;for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) {ans1=ans2=-1.0;for(int k = 1; k<=n; k++) {if(k == i || k == j) continue;double tmp = (p[k]-p[i])^(p[j]-p[i]);	if(sgn(tmp) > 0) ans1 = max(ans1,tmp);if(sgn(tmp) < 0) ans2 = max(ans2,-tmp);}if(ans1==-1.0 || ans2 == -1.0) continue;//这么用还是小心点、、、
//			cout << i << "***"<<j<< "***";
//			cout << ans1+ans2<<endl;ans = max(ans,ans1+ans2);}}printf("%.8f\n",ans/2);return 0 ;}
/*
4
0 0
0 5
5 0
1 1
*/

总结:

  sgn函数要用啊,,,double别直接等号判断,,很危险、、

   这是个坑啊,,还是自己太不小心了、、

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441074.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php网站的编辑器,5款适合PHP使用的HTML编辑器推荐

概述Web开发中&#xff0c;很多地方都会用到HTML编辑器(富文本编辑器)&#xff0c;我也用过几种&#xff0c;如UEditor、CkEditor等。这几天看了几篇文章&#xff0c;都是关于HTML编辑器的&#xff0c;写个文章记录下。推荐的编辑器simditor这个编辑器是前几天刚看到的&#xf…

【牛客 - 301哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级 )】小乐乐和25(模拟,技巧)

题干&#xff1a; 小乐乐特别喜欢25这个数字&#xff0c;他想把所有的数字都变成25的倍数。 现在小乐乐得到一个数字&#xff0c;想问问你最少用几次操作才可以把这个数字改造成25的倍数。 对于一次操作我们可以把相邻的两位做交换&#xff0c;比如123经过一次操作之后就可以…

怎么表示一个PHP语句块,php switch语句多个值匹配同一代码块应用示例

先说说switch()语句的格式switch(表达式){case 匹配1&#xff1a;当匹配1和表达式匹配成功执行的代码;break;case 匹配2&#xff1a;当匹配2和表达式匹配成功执行的代码;break;default&#xff1a;如果case语句没有与表达式成功所执行的代码;}理解 switch 是怎样执行的非常重要…

php查找顶级分类,php 无限级分类 获取顶级分类ID,php顶级_PHP教程

php 无限级分类 获取顶级分类ID&#xff0c;php顶级有这样一个表&#xff0c;id是分类的ID&#xff0c;name是分类名称&#xff0c;pid是上级分类的ID。现在有个分类ID&#xff0c;程序要找到它上级的上级的上级……分类的ID&#xff0c;简单说就是找出顶级分类的ID。比如“新鲜…

【POJ - 2392】Space Elevator (dp,优秀的背包问题)

题干&#xff1a; The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 < K < 400) different types of blocks with which to build the tower. Each block of type i has heigh…

php三种web开发技术,三种WEB开发主流技术ASP-PHP-JSP的评价

三种Web开发主流技术ASP-PHP-JSP的评价[摘要]本文从程序开发者的角度&#xff0c;对现今社会盛行的WEB开发技术进行了分析&#xff0c;旨在让WEB 开发人员、使用者、准备学习的人对WEB开发技术有更加深入的了解&#xff0c;并为WEB应用程序开发提供指导。[关键词]WEB开发技术 A…

*【CodeForces - 1088 ABC】套题比赛,A水题B模拟C构造D交互

A. Input The only line contains the integer xx (1≤x≤100)(1≤x≤100). Output You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (wit…

php 计算前几天,php计算几分钟前、几小时前、几天前的几个函数、类分享

搜索热词一、函数实现实例1&#xff1a;代码如下:function time_tran($the_time){$now_time date("Y-m-d H:i:s",time()8*60*60);$now_time strtotime($now_time);$show_time strtotime($the_time);$dur $now_time - $show_time;if($dur < 0){return $the_tim…

【CodeForces - 608D】Zuma(区间dp)

题干&#xff1a; Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Geno…

matlab没有int函数,matlab 未定义与 'char' 类型的输入参数相对应的函数 'int'。

最后你那zd句plot(int(k),double(s));里的int(k);不对。你如果想以k为横坐标&#xff0c;直接把int去掉&#xff0c;如回果非想要变成整数可以用floor(k);注&#xff1a;fix&#xff1a;向零取整 floor&#xff1a;向小取整 round&#xff1a;四舍五入 ceil&#xff1a;向...如…

【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列)

题干&#xff1a; It is so boring in the summer holiday, isnt it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each …

java读取yaml配置文件,snakeyaml读取yaml配置文件

下面上我解析yaml文件的例子&#xff1a;// me.yamlage: 1name: jiaobuchongparams:event: whats upurl: http://www.jiaobuchong.comfavoriteBooks:- Gone with the wind- The Little Prince对应的JavaBean类&#xff1a;// Me.javapublic class Me {private Integer age;priv…

算法讲解 -- 区间dp经典模型与优化(石子归并)

石子合并问题是最经典的DP问题。首先它有如下3种题型&#xff1a; PPT讲解&#xff1a;点击打开链接 (1)有N堆石子&#xff0c;现要将石子有序的合并成一堆&#xff0c;规定如下&#xff1a;每次只能移动任意的2堆石子合并&#xff0c;合并花费为新合成的一堆石子的数量。求将…

cpu影响matlab仿真速度吗,Proteus仿真速度很慢的分析

类型&#xff1a;行业软件大小&#xff1a;1.1M语言&#xff1a;中文 评分&#xff1a;6.5标签&#xff1a;立即下载这篇文章是我的个人实践经验&#xff1a;很多朋友在做Proteus硬件仿真的时候可能都碰上了仿真速度慢的问题&#xff0c;在点击了开始仿真之后&#xff0c;CPU过…

【HDU - 5900】QSC and Master(区间dp)

题干&#xff1a; Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University&#xff0c;You are facing the main building of Northeastern University.Ninety-nine percent of the students have not …

php set_timeout,和 JS 一样的 php setTimeout 函数

112016-07-11 21:34:11 08:00szopen 貌似没有复杂啊//enable ticksdeclare (ticks 1);//setTimeout event list$timeoutQueue new SplObjectStorage;register_tick_function(function() {global $timeoutQueue;foreach ($timeoutQueue as $v) {$callBack $v();if (is_callab…

mysql 7天自动拒单功能,mysql查询最近7天的数据,没有数据自动补0

select DATE( createtime) date , createtime, count(1) as count from order表 where DATEDIFF( now(), createtime)<7group by date ;12 月九号没有;给他在关联一张日期的表;--生成从今天开始完整的7天日期DECLARE LastSevenDaytable(day date)DECLARE StartDaydate …

【UVA - 10038】Jolly Jumpers (模拟,水题,标记)

题干&#xff1a; 题目大意&#xff1a; 要任意相邻的两个数的绝对值在[1,n)&#xff0c;而且这个范围内的每个数都要出现一次。 解题报告&#xff1a; 直接模拟就行了、 AC代码&#xff1a; #include<cstdio> #include<iostream> #include<algorithm> …

基于维纳滤波的语音增强算法 matlab,基于维纳滤波语音增强算法的改进实现

通过对维纳滤波的介绍,实现了基本维纳滤波效果;利用两级维纳滤波和两级滤波器组滤波方法实现了语音增强,达到了良好的效果。维普资讯 http://doc.docsou.com文章编号&#xff1a;0 2 8 8 (o 7 0 - 0 4 0 10—6 4 2 o )1 0 4 - 3基于维纳滤波语音增强算法的改进实现白文雅&#…

【CodeForces - 245H 】Queries for Number of Palindromes (带容斥的区间dp)

题干&#xff1a; Youve got a string s  s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |s|). The answer to the query is the number of …