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

我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多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.

最新文章

  1. mysql创建定时任务
  2. usb驱动开发11之设备生命线
  3. 网站启动SSL, http变为https后,session验证码错误解决方法
  4. pt-online-schema-change
  5. Android开发之DatePickerDialog与TimePickerDialog的功能和使用方法具体解释
  6. NTFS权限设置时卡死
  7. Aspose.Words 直接写response导出docx文档显示文件已损坏需要修复的解决办法
  8. 之前同事问到的一道python题目
  9. log4j.xml示例
  10. 影响HTTP性能的常见因素
  11. 织梦dedecms如何修改关键词的字数长度限制
  12. C#ComboBox绑定List
  13. Vue computed属性
  14. RPA流程自动化-Blueprism认证考试介绍
  15. 关于eclipse调试时程序控制台不能自动打开
  16. iis上的aps.net1.1程序池如何添加
  17. pandas 合并数据
  18. 中文分词 coreseek安装笔记
  19. html5 移动适配写法
  20. Java时间日期字符串格式转换大全

热门文章

  1. 单独调用Ueditor的图片上传功能
  2. .NET判断某一年的所有放假的日期
  3. Warning: session_start() [function.session-start]: Cannot send session cookie解决办法
  4. 零基础Android学习笔记-03 窗口间的数据传递
  5. ReactiveCocoa比较区分replay, replayLast和replayLazily
  6. 15个web前端的美轮美奂的 jQuery 图片特效
  7. c++之RTTI介绍
  8. 标签控制器,UITabBarController
  9. Oracle 创建用户授权
  10. 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法