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. 51nod1298 圆与三角形

    1298 圆与三角形 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三 ...

  2. E - A^B mod C (大数乘方取模)

    Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63) ...

  3. CodeDOMProvider 类

    CodeDomProvider 可用来创建和检索代码生成器和代码编译器的实例.代码生成器可以生成特定语言的代码,如:C#.Visual Basic.JScript 等,而代码编译器可以将代码文件编译成 ...

  4. RS485通信和Modbus协议(转)

    转自:http://www.51hei.com/bbs/dpj-23230-1.html 在工业控制.电力通讯.智能仪表等领域,通常情况下是采用串口通信的方式进行数据交换.最初采用的方式是RS232接 ...

  5. 解析SQLite中的常见问题与总结详解

    1. 创建数据如果不往数据库里面添加任何的表,这个数据库等于没有建立,不会在硬盘上产生任何文件,如果数据库已经存在,则会打开这个数据库. 2. 如何通过sqlite3.dll与sqlite3.def生 ...

  6. 如何向expect脚本里面传递参数

    如何向expect脚本里面传递参数   比如下面脚本用来做ssh无密码登陆,自动输入确认yes和密码信息,用户名,密码,hostname通过参数来传递   ssh.exp   Python代码   # ...

  7. AndroidStudio3.0 Canary 8注解报错Annotation processors must be explicitly declared now.

    体验最新版AndroidStudio3. Canary 8的时候,发现之前项目的butter knife报错,用到注解的应该都会报错 Error:Execution failed for task ' ...

  8. 用Python利用pyFirmata控制Arduino实现Blink

    2018-03-2809:20:44 arduino中有相应的库 1.安装pyFirmata包 pip install pyFirmata 在python2.7或python3.X下都可以执行. py ...

  9. php redis 操作大全

    类和方法 用法 Redis类 类RedisException 预定义的常量 Redis类 说明:创建一个Redis客户端 例 $redis = new Redis(); 类RedisException ...

  10. Windows离线安装Python第三方库的方法

    在window中,离线安装第三方模块, 1.下载第三方库的压缩文件,解压,将解压后的文件放到Python安装目录下的Lib\site_packages中 2. 将Python添加到环境变量里 3.进入 ...