裸半平面交,以前没写过,先写一遍再说

我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多4条边,就WA了)

 const
maxn=;
eps=1e-7;
type
point=record
x,y:double;
end;
poly=record
x,y,w:point;
end; var
a:array[..maxn]of poly;
n:longint; operator -(a,b:point)c:point;
begin
c.x:=a.x-b.x;
c.y:=a.y-b.y;
end; operator +(a,b:point)c:point;
begin
c.x:=a.x+b.x;
c.y:=a.y+b.y;
end; operator *(a:point;b:double)c:point;
begin
c.x:=a.x*b;
c.y:=a.y*b;
end; operator *(a,b:point)c:double;
begin
c:=a.x*b.y-a.y*b.x;
end; function wh(a:point):longint;
begin
with a do
begin
if abs(x)<eps then
if y>eps then exit()
else exit()
else
if abs(y)<eps then
if x>eps then exit()
else exit()
else
if x>eps then
if y>eps then exit()
else exit()
else
if y>eps then exit()
else exit();
end;
end; procedure swap(var x,y:poly);
var
t:poly;
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)>>].w;
repeat
while (wh(a[i].w)<wh(y)) or ((wh(a[i].w)=wh(y)) and (y*a[i].w+eps<)) do
inc(i);
while (wh(a[j].w)>wh(y)) or ((wh(a[j].w)=wh(y)) and (y*a[j].w>eps)) 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);
for i:= to n do
with a[i] do
begin
read(x.x,x.y,y.x,y.y);
w:=y-x;
end;
a[n+].x.x:=;
a[n+].x.x:=;
a[n+].x.y:=;
a[n+].x.y:=;
for i:= to do
begin
a[n+i+].y:=a[n+((i+)mod )+].x;
a[n+i+].w:=a[n+i+].y-a[n+i+].x;
end;
inc(n,);
sort(,n);
end; function get(a,b:poly):point;
var
s1,s2:double;
begin
s1:=a.w*(b.y-a.x);
s2:=a.w*(b.x-a.x);
if s1*s2>eps then s1:=-s1
else
begin
s1:=abs(s1);
s2:=abs(s2);
end;
if abs(s1+s2)<eps then get:=b.x
else get:=b.x+(b.w*(s2/(s1+s2)));
end; var
q:array[..maxn]of poly;
d:array[..maxn]of point;
l,r:longint;
ans:double; procedure work;
var
i:longint;
begin
l:=;
r:=;
q[]:=a[];
for i:= to n do
begin
while (l<r) and (a[i].w*(d[r-]-a[i].x)+eps<) do
dec(r);
while (l<r) and (a[i].w*(d[l]-a[i].x)+eps<) do
inc(l);
inc(r);
q[r]:=a[i];
if abs(q[r-].w*q[r].w)<eps then
begin
dec(r);
if a[i].w*(q[r].x-a[i].x)< then q[r]:=a[i];
end;
d[r-]:=get(q[r],q[r-]);
end;
while (l<r) and (q[l].w*(d[r-]-q[l].x)+eps<) do
dec(r);
if l<r then d[r]:=get(q[l],q[r]);
if r-l<= then writeln('0.0')
else
begin
for i:=l to r- do
ans:=ans+(d[i]*d[i+])/;
ans:=ans+(d[r]*d[l])/;
ans:=abs(ans);
if ans<eps then writeln('0.0')
else writeln(ans::);
end;
end; begin
init;
work;
end.

Uyuw's Concert POJ2451的更多相关文章

  1. poj 2451 Uyuw's Concert(半平面交)

    Uyuw's Concert Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8580   Accepted: 3227 De ...

  2. poj 2451 Uyuw's Concert (半平面交)

    2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...

  3. POJ2451 Uyuw's Concert (半平面交)

    POJ2451  给定N个半平面 求他们的交的面积. N<=20000 首先参考 POJ1279 多边形的核 其实就是这里要求的半平面交 但是POJ1279数据较小 O(n^2)的算法 看起来是 ...

  4. POJ2451 Uyuw's Concert(半平面交)

    题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...

  5. [poj2451]Uyuw's Concert

    半平面交滴裸题,但是要求nlogn,练练手 #include<iostream> #include<cstdio> #include<cmath> #include ...

  6. POJ 2451 Uyuw's Concert (半平面交)

    题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...

  7. poj 2451 Uyuw's Concert

    [题目描述] Remmarguts公主成功地解决了象棋问题.作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场. 这个位于自由三角洲联合王国(UDF,Unit ...

  8. POJ 2451 Uyuw's Concert(半平面交nlgn)

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> # ...

  9. bzoj 2451 Uyuw's Concert

    裸的半平面交.感觉这些东西,纯属在考代码能力啊.. #include<cstdio> #include<algorithm> #include<cmath> #de ...

随机推荐

  1. 将java项目打包成jar文件并在cmd运行

    保证java项目不报错能够通过运行 选择export 选择一个你要运行的程序入口Main方法 打开cmd,前提是你的javajdk及环境变量配置完成

  2. 【学习笔记】【C语言】数据

    1. 什么是数据 生活中时时刻刻都在跟数据打交道,比如体重数据.血压数据.股价数据等.在我们使用计算机的过程中,会接触到各种各样的数据,有文档数据.图片数据.视频数据,还有聊QQ时产生的文字数据.用迅 ...

  3. OC2-xml文件解析

    <?xml version="1.0" encoding="UTF-8"?> <Students class="17班" ...

  4. ThinkPHP快速入门

    ThinkPHP快速入门 1.ThinkPHP自动生成 当我们部署完ThinkPHP框架后,其会自动生成Application文件夹,如下图所示: 2.自动生成细节分析 问题1:Application ...

  5. 方法:一个简单的读取配置文件.properties的工具类 JAVA

    import java.util.ResourceBundle; public class ConfigHelper { private static ConfigHelper instance; p ...

  6. sizeWithFont方法被弃用了,该怎么办?

    之前使用了NSString类的sizeWithFont:constrainedToSize:lineBreakMode:方法,但是该方法已经被iOS7 Deprecated了,而iOS7新出了一个bo ...

  7. 使用 Time Machine 恢复 .ssh等隐藏文件夹

    重装MAC系统后,要恢复.ssh等文件夹内容,而其在“Finder”中又是默认隐藏的,这时我们可以先在“Finder”中使用“前往文件夹功能…”进入指定文件夹,然后再进入“Time Machine”进 ...

  8. yum被锁定

    使用Yum的时候 提示yum被搜定了 . Another app is currently holding the yum lock; waiting for it to exit...   解决办法 ...

  9. WIN10主动推升级,有点意思

    不论正与盗,皆推升级,是否一样可用?

  10. 惠普M1005打印机无法自动进纸的问题

    惠普M1005打印机无法自动进纸的问题 问题起因 其实我也不太清楚是什么起因,前一天用的好好的惠普M1005打印机,在打印时没有直接打印,会弹出一个提示对话框,同时打印机显示屏上显示“load tra ...