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. c语言小项目-使用mysql数据库的图书管理系统

    VS2013通过MySQL方式连接到MySQL MySQL官网上C++的API有两个.一个是很成熟的mysql++,另一个是MySQL Connector/C++,近两年才出的,模仿JDBC做的,封装 ...

  2. Codeforces 1131 (div 2)

    链接:http://codeforces.com/contest/1131 A Sea Battle 利用良心出题人给出的图,不难看出答案为\(2*(h1+h2)+2*max(w1,w2)+4\)由于 ...

  3. 397 Integer Replacement 整数替换

    给定一个正整数 n,你可以做如下操作:1. 如果 n 是偶数,则用 n / 2替换 n.2. 如果 n 是奇数,则可以用 n + 1或n - 1替换 n.n 变为 1 所需的最小替换次数是多少?示例 ...

  4. OpenSSL 1.0.0生成p12、jks、crt等格式证书的命令个过程

    OpenSSL 1.0.0生成p12.jks.crt等格式证书的命令个过程   此生成的证书可用于浏览器.java.tomcat.c++等.在此备忘!     1.创建根证私钥命令:openssl g ...

  5. 16 继续讲C#中的条件执行。if...else if...else

    if...else...语句可以让我们判断两种情况.当条件为真的时候,执行一部分:当条件为假的时候,执行另一部分.如果我们需要判断3种,4种,5种情况,那我们应该怎么办呢? 在C#中我们可以 使用if ...

  6. 如何手工搭建本地Yum仓库

    如何手工搭建本地Yum仓库(重点推荐)  https://www.linuxidc.com/Linux/2016-09/135480.htm CentOS7.2 创建本地YUM源和局域网YUM源: h ...

  7. [ HAOI 2008 ] 圆上的整点

    \(\\\) Description 给出一个整数 \(r\) ,求圆 \(x^2+y^2=r^2\) 上的整点数. \(r\le 2\times 10^9\) \(\\\) Solution 神题. ...

  8. php域名授权只需要一个函数

    <?php function allow_doamin(){ $is_allow=false; $url=trim($_SERVER['SERVER_NAME']); $arr_allow_do ...

  9. Android 网络图片查看器与网页源码查看器

    在AndroidManifest.xml里面先添加访问网络的权限: <uses-permission android:name="android.permission.INTERNET ...

  10. Smarty的应用

    smarty模板的核心是一个类,下载好的模板中有这么几个重要的文件夹 (1)libs核心文件夹(2)int.inc.php这是入口文件(3)plugins:自己写的插件文件夹(4)templates_ ...