Codeforces Round #198 (Div. 2) B. Maximal Area Quadrilateral
1 second
256 megabytes
standard input
standard output
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.
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 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 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.
5
0 0
0 4
4 0
4 4
2 3
16.000000
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.
题 意就是找4个点,求最大的四边形的面积,枚举对角线,我们可以求出上三角形的最大值,和下三角形的最大值,这样,我们就可以得出最大的四边形的面积,用叉积可以得出面积,还可以通过其正负,得出是上三角形,还是下三角形,这样,就可以得到了n^3的算法了!
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define M 350
#define eps 0
#define inf 10000000000
struct node {
double x,y;
}p[M];
double mul(int i,int j,int k){
return ((p[k].x-p[i].x)*(p[k].y-p[j].y)-(p[k].y-p[i].y)*(p[k].x-p[j].x))/2.0;
}
int main()
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
double lmax=-inf,rmax=-inf,amax=-inf;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i==j)
continue;
lmax=-inf,rmax=-inf;
for(k=0;k<n;k++){
if(i==k||j==k)
continue;
double temp=mul(i,j,k);
if(temp<eps){
lmax=max(lmax,-temp);
}
else {
rmax=max(rmax,temp);
}
}
amax=max(amax,lmax+rmax);
// printf("%.6f %.6ffdsf\n",amax,lmax+rmax);
}
}
printf("%.6f\n",amax);
}
return 0;
}
Codeforces Round #198 (Div. 2) B. Maximal Area Quadrilateral的更多相关文章
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #198 (Div. 2)
A.The Wall 题意:两个人粉刷墙壁,甲从粉刷标号为x,2x,3x...的小块乙粉刷标号为y,2y,3y...的小块问在某个区间内被重复粉刷的小块的个数. 分析:求出x和y的最小公倍数,然后做一 ...
- Codeforces Round #198 (Div. 1 + Div. 2)
A. The Wall 求下gcd即可. B. Maximal Area Quadrilateral 枚举对角线,根据叉积判断顺.逆时针方向构成的最大面积. 由于点坐标绝对值不超过1000,用int比 ...
- Codeforces Round #198 (Div. 2) D. Bubble Sort Graph (转化为最长非降子序列)
D. Bubble Sort Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [置顶] Codeforces Round #198 (Div. 1)(A,B,C,D)
http://codeforces.com/contest/341 赛后做的虚拟比赛,40分钟出了3题,RP爆发. A计数问题 我们可以对每对分析,分别对每对<a, b>(a走到b)进行统 ...
- Codeforces Round #506 (Div. 3) C. Maximal Intersection
C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #198 (Div. 2) E. Iahub and Permutations —— 容斥原理
题目链接:http://codeforces.com/contest/340/problem/E E. Iahub and Permutations time limit per test 1 sec ...
- Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest
链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...
- Codeforces Round #198 (Div. 2)C,D题解
接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...
随机推荐
- sql 月初和月末
--月初 select convert(varchar(10),dateadd(day,-(day(getdate()) -1),getdate()) ,120) --月末select conve ...
- spring jar包冲突
在用Spring+Hibernate做项目时候遇到java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit 网上查得答案 环境 ...
- 利用Apperance协议定义View的全局外观
假设要定义一个全局的bkColor用于背景颜色 1.@property(nonatomic,strong)UIColor *bkColor UI_APPEARANCE_SELECTOR; 2.在下面方 ...
- ##DAY5 UIControl及其子类
##DAY5 UIControl及其子类 #pragma mark ———————UIControl——————————— UIControl初识: 1)UIControl是有控制功能的视图(比如UI ...
- union 和 union all 有什么不同?
假设我们有一个表 Student, 包括以下字段与数据:drop table student;create table student( idint primary key,name nvarchar ...
- 下 面 这 条 语 句 一 共 创 建 了 多 少 个 对 象 : String s="a"+"b"+"c"+"d";
javac 编译可以对字符串常量直接相加的表达式进行优化, 不必要等到运行期去进行加法运算处理, 而是在编译时去掉其中的加号, 直接将其编译成一个这些常量相连的结果.题目中的第一行代码被编译器在编译时 ...
- PHP-购物网站开发设计(一)
2015-07-6 开始使用PHP完成简单购物网站的设计,首先要选择合适的软件平台,所以今天先记录平台的选择与搭建: 我选择使用Apache24 + PHP 5.6 + MySQL 开发环境完成PHP ...
- hadoop 主节点存储告警
之前只他调整过dfs 的存储目录到最大配额的目录,其它没有处理(就是在默认的/ 目录下,而这个目录的存储配额只有50G) 运行一周的时间不到,集群开始告警,查看是目录/ 的存储占用超过了60% 再查看 ...
- 简单的Coretext 图文混排
在很多新闻类或有文字展示的应用中现在都会出现图文混排的界面例如网易新闻等,乍一看去相似一个网页,其实这样效果并非由UIWebView 加载网页实现.现在分享一种比较简单的实现方式 iOS sdk中为我 ...
- 菜农群课笔记之ICP与ISP----20110412(整理版)
耗时一上午时间对HOT大叔昨晚的群课内容进行温故并整理,现将其上传,若想看直播可到下面链接处下载:http://bbs.21ic.com/icview-229746-1-1.html 成 ...