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

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

    很高兴来到博客园!迈入这座知识的殿堂,实是幸运.这是我的第一篇博客,开启丰富有趣的学习之旅,同时,我希望和大家一起学习一起进步,Let‘s go! <!DOCTYPE html PUBLIC & ...

  2. DNS map file in windows

    Edit "C:\WINDOWS\system32\drivers\etc\hosts", add the IP to DNS name mapping.

  3. PHP中大括号{}用法总结

    刚用到一个由字符串来设定对像属性名的功能.发现大括号的作用真强…. 1. 动态设置对象的属性名的使用:写法一(不能正确设置): $obj->$string[$key]; //这里只能使用$str ...

  4. iOS - 表格

    一. TableView 1.1 StoryBoard方式 1.2 nib方式 1.2.1 一般 1.2.2 自定义单元格 1.3 纯代码方式 (1) 简单表视图操作 Step1: 实现协议 2个协议 ...

  5. 【学习笔记】【C语言】break和continue

    1.使用 break: 1.使用场合 1> switch语句:退出整个switch语句 2> 循环结构:退出整个循环语句   * while   * do while   * for 2. ...

  6. Application 统计在线人数

    MVC 统计在线人数: protected void Application_Start() { Application[; AreaRegistration.RegisterAllAreas(); ...

  7. http: URL、请求方式

    URL:统一资源定位符,可以从互联网得到和访问资源,是标准资源的位置 结构包括协议.服务器名称(IP地址).端口(有的服务器需要).路径.文件名 协议:告诉浏览器如何处理打开的文件,常用的就是http ...

  8. mysql max_allowed_packet自动重置为1024 终结解决

    背景: 测试环境1台centOS机器,最近一段频繁报“ Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too ...

  9. 4.Servlet_Form表单处理

    1.建项目"3Servlet_Form",src下建包“com.amaker.servlet”,web-root下建Register.html <!DOCTYPE html& ...

  10. 关于ionic的跨域问题

    例如你的api原地址请求是 http://10.100.100.100:8080/service/, 1.那么你应该在项目内api请求改成 /service/, 注意红色部分是ionic serve ...