Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made makes John mad. So he wants to restrict the area Betsy can run. There are nn (4<n\le 20000004<n≤2000000) points of interest (or POI) on the farm, the i-th one located at (x_i,y_i)(x​i​​,y​i​​), 0\le |x_i |,|y_i |\le 10^60≤∣x​i​​∣,∣y​i​​∣≤10​6​​. So farmer John said: You can select four points, and the area you can run is the convex hull of the four points you select. Betsy is clever, but she doesn't like computing, so she asked you for help to calculate the max area she can run.

Important note

There are at most 20 test cases in your input. 18 of them satisify n\le 2000n≤2000. And the ramaining two testcases are generated in random. The max size of input file is about 60MB. Please, use fast input methods (for example, please use BufferedReader instead of Scanner for Java, and scanf instead of cin for C++).

Input

Input contains multiple cases, please process to the end of input. The first line of each test cases contains an integer nn, the number of POI. The following nn lines, contains two integers, x_i,y_ix​i​​,y​i​​, the location of ii-th POI.

Output

For each test case, print one line with your answer, your answer should keep exactly one decimal place.

Sample Input

4
0 0
1 0
1 1
0 1
4
1 1
2 2
3 3
4 4

Sample Output

1.0
0.0 原题是BZOJ1069 首先求个凸包,然后在凸包上面枚举两点,找到它两边能组成的最大三角形即可,这个三角形可用2-
pointer的方式,就是找凸包上关于某一条线最远的点,复杂度是n^2
n的范围虽然很大,但是n个点都是随机生成的,求凸包后会丢弃大量的点
求凸包用的是基于水平序的Graham_Scan算法
需要注意的是求叉积和面积的时候可能会超出int类型,需要转double
#include<algorithm>
#include<iostream>
#include<fstream>
#include<math.h>
#include<stdio.h>
using namespace std; int n;
typedef struct{
int x,y;
}Point; Point a[];
Point b[];
int q[],top;
int ans[]; bool cmp(Point a,Point b){
return a.y<b.y||(a.y==b.y&&a.x<b.x);
} //int转double的技巧
double cross(int i,int j,int k){
Point a1=a[i];
Point b=a[j];
Point c=a[k];
return 1.0*(c.x-b.x)*(a1.y-b.y)-1.0*(c.y-b.y)*(a1.x-b.x);
} void scan(){
q[]=;q[]=;top=;
for(int i=;i<=n;++i)
{
while(top>&&cross(q[top-],q[top],i)<=) top--;
q[++top]=i;
} for(int i=;i<=top;++i)
ans[i]=q[i];
ans[]=top; q[]=n;q[]=n-;top=;
for(int i=n-;i>=;--i)
{
while(top>&&cross(q[top-],q[top],i)<=) top--;
q[++top]=i;
} for(int i=;i<top;++i)
{
ans[]++;
ans[ans[]]=q[i];
}
} //int转double的技巧
double area(int i,int j,int k){
Point a1=a[ans[i]];
Point b=a[ans[j]];
Point c=a[ans[k]];
return fabs((1.0*(c.x-b.x)*(a1.y-b.y)-1.0*(c.y-b.y)*(a1.x-b.x))/); } double max_area=;
double left_area=;
double right_area=;
int main(){
while(~scanf("%d",&n)){
max_area=;
for(int i=;i<=n;++i)
scanf("%d %d",&b[i].x,&b[i].y); sort(b+,b+n+,cmp); //去除重复点
int len=;
a[]=b[];
int i=;
while(i<=n)
{
while(i<=n&&b[i].x==b[i-].x&&b[i].y==b[i-].y) i++;
if(i<=n)
a[++len]=b[i];
i++;
}
n=len; //水平序扫描构造凸包
scan(); if(ans[]<=) {printf("0.0\n");continue;}
if(ans[]==) {printf("%.1f\n",area(,,));continue;} int r,l,d;
for(int i=;i<=ans[];++i)
{
r=i+;
l=i+;
if(i+>ans[]) continue;//第4个点不应该超过最后一个凸包节点,不然就重复计算了
for(int j=i+;j<=ans[];++j)
{
if(i==&&j==ans[]) continue; while(r+<j&&area(i,j,r)<=area(i,j,+r)) r++;
right_area=area(i,j,r); while(l+<=ans[]&&area(i,j,l)<=area(i,j,l+)) l++;
left_area=area(i,j,l); if(right_area+left_area>max_area) max_area=right_area+left_area;
}
}
printf("%.1f\n",max_area); } }


武大OJ 706.Farm的更多相关文章

  1. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  2. 武大OJ 574. K-th smallest

    Description Give you a number S of length n,you can choose a position and remove the number on it.Af ...

  3. 武大OJ 622. Symmetrical

    Description          Cyy likes something symmetrical, and Han Move likes something circular. Han Mov ...

  4. 武大OJ 613. Count in Sama’s triangle

    Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up w ...

  5. 武大OJ 612. Catch the sheep

    Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, tou ...

  6. BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场

    题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 491  S ...

  7. Online Judge(OJ)搭建(第一版)

    搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...

  8. SharePoint 2013: A feature with ID has already been installed in this farm

    使用Visual Studio 2013创建一个可视web 部件,当右击项目选择"部署"时报错: "Error occurred in deployment step ' ...

  9. 1Z0-053 争议题目解析706

    1Z0-053 争议题目解析706 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 706.You execute the following command to set the ...

随机推荐

  1. 基于itchat实现微信群消息同步机器人

    原始网址:http://www.jianshu.com/p/7aeadca0c9bd# 最近 全栈数据工程师养成攻略 的微信群已经将近500人,开了二群之后为了打通不同微信群之间的消息,花了点时间做了 ...

  2. MyEclipse无法自动编译项目故障一例

    MyEclipse导入项目后发现无法自动编译,classes目录下没有编译的类. 尝试的解决方法: 1.刷新项目,失败: 2.project->clean-,失败: 3.关闭项目再次打开,失败: ...

  3. Spring抽象JDBC,使用JdbcTemplate

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  4. 计算科学(转自wiki)

    计算科学(也称科学计算 scientific computation 或 SC)是一个快速增长的多学科领域,使用先进的计算能力来理解和解决复杂的问题. 计算科学包括三个不同的方面: 1. 开发用于解决 ...

  5. Docker学习系列(二):Docker三十分钟快速入门(上)

    一.背景 ​ 最近,Docker技术真是一片火热,它的出现也弥补了虚拟机资源消耗过高的问题,直接让虚拟化技术有了质的飞跃.那么本文我们来聊一聊Docker,和大家一起认识Docker,简单入门Dock ...

  6. Disruptor源码解读

    上一篇已经介绍了Disruptor是什么?简单总结了为什么这么快?下面我们直接源码搞起来,简单粗暴.高性能队列disruptor为什么这么快? 一.核心类接口 Disruptor 提供了对RingBu ...

  7. Android Error:Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'.

    问题:Error:Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List ...

  8. ubantu MongoDB安装

    转 https://blog.csdn.net/flyfish111222/article/details/51886787 本博文介绍了MongoDB,并详细指引读者在Ubuntu下MongoDB的 ...

  9. Android基础TOP6_1:FrameLyayout和ImageView制作层叠图片

    Activity: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...

  10. Statement和PreparedStatement深入学习总结

    最近在看java安全编码方面的书籍,在看到SQL注入漏洞的问题时,引发了我对Statement和PreparedStatement深入总结的欲望,废话少说,下面咱们就正式开始. 当初始的SQL查询被修 ...