Uyuw's Concert POJ2451
裸半平面交,以前没写过,先写一遍再说
我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多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的更多相关文章
- poj 2451 Uyuw's Concert(半平面交)
Uyuw's Concert Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8580 Accepted: 3227 De ...
- poj 2451 Uyuw's Concert (半平面交)
2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...
- POJ2451 Uyuw's Concert (半平面交)
POJ2451 给定N个半平面 求他们的交的面积. N<=20000 首先参考 POJ1279 多边形的核 其实就是这里要求的半平面交 但是POJ1279数据较小 O(n^2)的算法 看起来是 ...
- POJ2451 Uyuw's Concert(半平面交)
题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...
- [poj2451]Uyuw's Concert
半平面交滴裸题,但是要求nlogn,练练手 #include<iostream> #include<cstdio> #include<cmath> #include ...
- POJ 2451 Uyuw's Concert (半平面交)
题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...
- poj 2451 Uyuw's Concert
[题目描述] Remmarguts公主成功地解决了象棋问题.作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场. 这个位于自由三角洲联合王国(UDF,Unit ...
- POJ 2451 Uyuw's Concert(半平面交nlgn)
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> # ...
- bzoj 2451 Uyuw's Concert
裸的半平面交.感觉这些东西,纯属在考代码能力啊.. #include<cstdio> #include<algorithm> #include<cmath> #de ...
随机推荐
- IOS显示九宫格列表
//总列数 ; CGFloat appW = ; CGFloat appH = ; //间隙 CGFloat maginX = (self.view.frame.size.width - totalC ...
- C#中winform窗体如何嵌入cmd命令窗口
解决方法一: 自己放一个文本框,改成黑色,然后输入命令,执行时,你Process.Start cmd ,此时CMD窗口不显示,然后,将CMD的返回值,再取出来,设回文本框. 如何用这种方法实时获取cm ...
- Newtonsoft.Json 基本用法
Newtonsoft.Json 是.net 开源的一个json格式处理类库 官方网站:http://json.codeplex.com/ 在使用的项目引用Newtonsoft.Json库.平常使用的方 ...
- dreamweaver基础1
文本enter回车 (隔着一行)SHIFT+enter回车 (换行不分段)网页图片格式:最优化:在保证画质前提下尽可能是图片数据量小一些.(gif,数据量小,带有动画信息,实现透明背景,但只支持256 ...
- OC9_代理正向传值
// // ProtectedDeleagate.h // OC9_代理正向传值 // // Created by zhangxueming on 15/6/24. // Copyright (c) ...
- SpringMvc入门二----HelloWorld
1. 导入需要的架包: 2. 配置web.xml,添加Servlet <servlet> <servlet-name>springmvc</servlet-name> ...
- Vim 保存和退出命令
命令 简单说明 :w 保存编辑后的文件内容,但不退出vim编辑器.这个命令的作用是把内存缓冲区中的数据写到启动vim时指定的文件中. :w! 强制写文件,即强制覆盖原有文件.如果原有文件的访问权限不允 ...
- [windows phone开发]新生助手的开发过程与体会一
功能需求分析: 1. 为到达学院的新生指路,给出所有路线,并给出必要提示: 2. 对学院建筑进行介绍: 3. 对学院周边环境(交通.购物.银行等)进行介绍: 4. 必要的应用设置 总体设计: ...
- mysql中按string字段排序
如: Sql代码SELECT * FROM Student WHERE 1 = 1 ORDER BY -ID DESC或者: Sql代码SELECT * FROM Student WHERE 1 = ...
- 信号处理程序(signal handler)会被重置的信号
首先说明我的系统,CentOS 6.6,内核为2.6.32-504.12.2.el6.i686. 当用signal对某个信号设定信号处理函数的时候,有些信号的处理函数会被重置,有些则不会,这种情况的具 ...