Description

在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大。
Input

第1行一个正整数N,接下来N行,每行2个数x,y,表示该点的横坐标和纵坐标。
Output

最大的多边形面积,答案精确到小数点后3位。
Sample Input
5
0 0
1 0
1 1
0 1
0.5 0.5
Sample Output
1.000

HINT

数据范围 n<=2000, |x|,|y|<=100000

先求凸包

然后枚举四边形的对角线,分别找到距离最远的两个点更新答案(这两个点都是单调的),总复杂度是O(n^2)的

哪里写挫了,超慢,总时间1600ms

 const
maxn=;
type
point=record
x,y:double;
end;
var
a:array[..maxn]of point;
n:longint;
min:point; function cj(a,b,c:point):double;
begin
exit((a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y));
end; procedure swap(var x,y:point);
var
t:point;
begin
t:=x;x:=y;y:=t;
end; procedure sort(l,r:longint);
var
i,j:longint;
y:point;
begin
i:=l;
j:=r;
y:=a[(l+r)>>];
repeat
while cj(y,a[i],min)< do
inc(i);
while cj(y,a[j],min)> do
dec(j);
if i<=j then
begin
swap(a[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end; procedure init;
var
i:longint;
begin
read(n);
min.x:=maxlongint;
min.y:=maxlongint;
for i:= to n do
begin
read(a[i].x,a[i].y);
if (a[i].x<min.x) or ((a[i].x=min.x) and (a[i].y<min.y)) then min:=a[i];
end;
i:=n;
while i> do
begin
if (a[i].x=min.x) and (a[i].y=min.y) then
begin
a[i]:=a[n];
dec(n);
end
else dec(i);
end;
sort(,n);
inc(n);
a[n]:=min;
a[]:=min;
end; var
q:array[..maxn]of longint;
f:array[..maxn,..]of double;
tot,lasta,lastb:longint;
ans:double; function up(var x:double;y:double):boolean;
begin
if x<y then
begin
x:=y;
exit(true);
end;
exit(false);
end; function down(var x:double;y:double):boolean;
begin
if x>y then
begin
x:=y;
exit(true);
end;
exit(false);
end; procedure work;
var
i,j:longint;
begin
for i:= to n do
begin
while (tot>) and (cj(a[i],a[q[tot]],a[q[tot-]])>=) do
dec(tot);
inc(tot);
q[tot]:=i;
end;
for i:= to tot- do
begin
f[i+,]:=-maxlongint;
f[i+,]:=;
for j:= to n do
if up(f[i+,],cj(a[q[i+]],a[q[j]],a[q[i]])) then lasta:=j;
lastb:=i;
for j:=i+ to tot do
begin
f[j,]:=cj(a[q[j]],a[q[lasta]],a[q[i]]);
f[j,]:=cj(a[q[j]],a[q[lastb]],a[q[i]]);
while up(f[j,],cj(a[q[j]],a[q[lasta mod tot+]],a[q[i]])) do
lasta:=lasta mod tot+;
while down(f[j,],cj(a[q[j]],a[q[lastb mod tot+]],a[q[i]])) do
lastb:=lastb mod tot+;
up(ans,f[j,]-f[j,]);
end;
end;
writeln(ans/::);
end; begin
init;
work;
end.

1069: [SCOI2007]最大土地面积 - BZOJ的更多相关文章

  1. bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2277  Solved: 853[Submit][Stat ...

  2. BZOJ 1069: [SCOI2007]最大土地面积 [旋转卡壳]

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2978  Solved: 1173[Submit][Sta ...

  3. BZOJ 1069: [SCOI2007]最大土地面积(旋转卡壳)

    题目链接~ 1069: [SCOI2007]最大土地面积 思路很简单,极角排序求完凸包后,在凸包上枚举对角线,然后两边分别来两个点旋转卡壳一下,搞定! 不过计算几何的题目就是这样,程序中间的处理还是比 ...

  4. 1069: [SCOI2007]最大土地面积

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2961  Solved: 1162[Submit][Sta ...

  5. 【BZOJ】1069: [SCOI2007]最大土地面积(凸包+旋转卡壳)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1069 显然这四个点在凸包上,然后枚举两个点找上下最大的三角形即可. 找三角形表示只想到三分QAQ.. ...

  6. ●BZOJ 1069 [SCOI2007]最大土地面积

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1069 题解: 计算几何,凸包,旋转卡壳 其实和这个题差不多,POJ 2079 Triangl ...

  7. bzoj 1069 [SCOI2007]最大土地面积——旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1069 发现 n 可以 n^2 .所以枚举对角线,分开的两部分三角形就可以旋转卡壳了. 注意坐 ...

  8. [BZOJ]1069: [SCOI2007]最大土地面积

    题目大意:给出二维平面上n个点,求最大的由这些点组成的四边形面积.(n<=2000) 思路:求出凸包后旋转卡壳枚举对踵点对作为四边形的对角线,枚举或二分另外两个点,复杂度O(n^2)或O(nlo ...

  9. bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳

    题目大意: 二维平面有N个点,选择其中的任意四个点使这四个点围成的多边形面积最大 题解: 很容易发现这四个点一定在凸包上 所以我们枚举一条边再旋转卡壳确定另外的两个点即可 旋(xuan2)转(zhua ...

随机推荐

  1. ListViewDemo

    ListView Layout示例:MainActivity.java中定义待显示的数据countryArray, 在activity_main中定义ListView,activity_listvie ...

  2. windowSoftInputMode属性详解

    转自:http://blog.csdn.net/twoicewoo/article/details/7384398 activity主窗口与软键盘的交互模式,可以用来避免输入法面板遮挡问题,Andro ...

  3. 通过带参数的Sql语句来实现模糊查询(多条件查询)

    #region 通过带参数的Sql语句来实现模糊查询(多条件查询) StringBuilder sb = new StringBuilder("select * from books&quo ...

  4. Java类加载的时机_4种主动引用会触犯类加载+剩下的被动引用不会触发类的加载

    转载自:http://chenzhou123520.iteye.com/blog/1597597 Java虚拟机规范没有强制性约束在什么时候开始类加载过程,但是对于初始化阶段,虚拟机规范则严格规定了有 ...

  5. 两种获取connectionString的方式

    两种获取connectionString的方式 1. public static string connectionString = ConfigurationManager.ConnectionSt ...

  6. Cocos2d-x 3.0标签类Label

    Cocos2d-x 3.0后推出了新的标签类Label,这种标签通过使用FreeType[1]来使它在不同的平台上有相同的视觉效果.由于使用更快的缓存代理,它的渲染也将更加快速.Label提供了描边和 ...

  7. VxWorks 6.9 内核编程指导之读书笔记 -- C++开发

    5.1 介绍 针对C++的VxWorks配置 C++头文件 使用C++启动任务 C和C++之前调用代码 C++编译器说明 在信号处理和ISR中使用C++ 下载C++编写的内核模块 C++编译器的不同 ...

  8. Tomcat7出现HTTP Status 500 - java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.el.ELContextImpl

    今天在Tomcat7上发布了一个war,过一阵子发现localhost:8080都进不去了.在浏览器输入http://localhost:8080出现如下内容:

  9. JS运动学习笔记 -- 任意值的运动框架(高/宽度,背景颜色,文本内容,透明度等)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. css3学习笔记之按钮

    基本按钮样式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <!DOCTYPE ht ...