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

我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多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. Part 82 to 85 Talking about Generic queue, stack collection class

    Part 82   Generic queue collection class Part 83   Generic stack collection class Part 84   Real tim ...

  2. 别人网站生成的json

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sb.ToString()); WebResponse rep = req.GetResp ...

  3. MVC自定义错误页404静态页

    昨天公司要求给所有项目添加自定义404错误页,具体的要求实现的有以下几点: 1.实现自定义错误(如各种error,404等)跳转到指定的页面 2.所指定的页面输出的http状态值必须是404或其他指定 ...

  4. JAVA:变量,数据类型,运算符,流程控制(简介)<1>

    一.安装和配置jdk 1.jdk是什么? (1).jdk全称是Java Development Kit, Java开发工具包; (2).jdk是sun公司开发的; (3).jdk主要包括:jre(Ja ...

  5. (转)为首次部署MongoDB做好准备:容量计划和监控

    如果你已经完成了自己新的MongoDB应用程序的开发,并且现在正准备将它部署进产品中,那么你和你的运营团队需要讨论一些关键的问题: 最佳部署实践是什么? 为了确保应用程序满足它所必须的服务层次我们需要 ...

  6. 会场安排问题—NYOJ14

    时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就是安排学校 ...

  7. ABAP OO与ALV结合方式探索(1)

    用OO来开发,尤其是在复杂业务的开发过程中 从程序设计的角度而言,应该更简单一点 而ALV是二次开发中登场很高的一个控件 最近做了一些尝试,探索OO的代码和ALV的结合使用   使用控件型的ALV A ...

  8. 【风马一族_Java】在某个范围内,找出具有水仙花特征的数字

    打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如: 153是一个"水仙花数",因为153=1的三 ...

  9. silverlight 文本框只能输入数字

    void mobile_KeyUp(object sender, KeyEventArgs e) { Regex rg = new Regex("^[0-9]{1,11}$"); ...

  10. MSSQL优化之——查看语句执行情况

    MSSQL优化之——查看语句执行情况 在写SQL语句时,必须知道语句的执行情况才能对此作出优化.了解SQL语句的执行情况是每个写程序的人必不可少缺的能力.下面是对查询语句执行情况的方法介绍. 一.设置 ...