题目描述 Description

输入n个矩形,求他们总共占地面积(也就是求一下面积的并)

输入描述 Input Description

可能有多组数据,读到n=0为止(不超过15组)

每组数据第一行一个数n,表示矩形个数(n<=100)

接下来n行每行4个实数x1,y1,x2,y1(0 <= x1 < x2 <= 100000;0 <= y1 < y2 <= 100000),表示矩形的左下角坐标和右上角坐标

输出描述 Output Description

每组数据输出一行表示答案

样例输入 Sample Input

2
    10 10 20 20
    15 15 25 25.5
    0

样例输出 Sample Output

180.00

水题,我只是拿来练习扫描线的

 const
maxn=;
type
node=record
l,r,lc,rc,cnt:longint;
sum,cover:double;
end;
var
tree:array[..maxn*]of node;
x:array[..maxn*]of double;
l,r,c:array[..maxn*]of longint;
y,lll,rrr:array[..maxn*]of double;
n,tot,ll,rr:longint;
ans:double; procedure swap(var x,y:longint);
var
t:longint;
begin
t:=x;x:=y;y:=t;
end; procedure swap(var x,y:double);
var
t:double;
begin
t:=x;x:=y;y:=t;
end; procedure sort(l,r:longint);
var
i,j:longint;
y:double;
begin
i:=l;
j:=r;
y:=x[(l+r)>>];
repeat
while x[i]<y do
inc(i);
while x[j]>y do
dec(j);
if i<=j then
begin
swap(x[i],x[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 build(l,r:longint);
var
now,mid:longint;
begin
inc(tot);
now:=tot;
tree[now].l:=l;
tree[now].r:=r;
with tree[now] do
begin
cover:=;
cnt:=;
if l=r then
begin
sum:=x[r+]-x[r];
lc:=;
rc:=;
exit;
end;
mid:=(l+r)>>;
lc:=tot+;
build(l,mid);
rc:=tot+;
build(mid+,r);
sum:=x[r+]-x[l];
end;
end; procedure sort2(ll,rr:longint);
var
i,j:longint;
z:double;
begin
i:=ll;
j:=rr;
z:=y[(ll+rr)>>];
repeat
while y[i]<z do
inc(i);
while y[j]>z do
dec(j);
if i<=j then
begin
swap(l[i],l[j]);
swap(r[i],r[j]);
swap(y[i],y[j]);
swap(c[i],c[j]);
inc(i);
dec(j);
end;
until i>j;
if i<rr then sort2(i,rr);
if j>ll then sort2(ll,j);
end; function find(k:double):longint;
var
l,r,mid:longint;
begin
l:=;
r:=n*;
while l<>r do
begin
mid:=(l+r)>>;
if x[mid]=k then exit(mid);
if x[mid]>k then r:=mid-
else l:=mid+;
end;
exit(l);
end; procedure init;
var
i:longint;
x1,y1,x2,y2:double;
begin
read(n);
if n= then halt;
ans:=;
tot:=;
for i:= to n do
begin
read(x1,y1,x2,y2);
lll[i*-]:=x1;
rrr[i*-]:=x2;
y[i*-]:=y1;
c[i*-]:=;
lll[i*]:=x1;
rrr[i*]:=x2;
y[i*]:=y2;
c[i*]:=-;
x[i*-]:=x1;
x[i*]:=x2;
end;
sort(,n*);
build(,n*-);
for i:= to n* do
begin
l[i]:=find(lll[i]);
r[i]:=find(rrr[i]);
end;
sort2(,n*);
end; procedure insert(now,c:longint);
var
mid:longint;
begin
with tree[now] do
begin
if (ll<=l) and (rr>=r) then
begin
inc(cnt,c);
if cnt> then cover:=sum
else cover:=tree[lc].cover+tree[rc].cover;
exit;
end;
mid:=(l+r)>>;
if ll<=mid then insert(lc,c);
if rr>mid then insert(rc,c);
if cnt> then cover:=sum
else cover:=tree[lc].cover+tree[rc].cover;
end;
end; procedure work;
var
i:longint;
begin
for i:= to n* do
begin
if y[i]<>y[i-] then ans:=ans+tree[].cover*(y[i]-y[i-]);
ll:=l[i];
rr:=r[i]-;
insert(,c[i]);
end;
writeln(ans::);
end; begin
while true do
begin
init;
work;
end;
end.

3044 矩形面积求并 - Wikioi的更多相关文章

  1. codves 3044 矩形面积求并

    codves  3044 矩形面积求并  题目等级 : 钻石 Diamond 题目描述 Description 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入描述 Input Desc ...

  2. codevs 3044 矩形面积求并

    3044 矩形面积求并   题目描述 Description 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入描述 Input Description 可能有多组数据,读到n=0为止(不 ...

  3. poj1151==codevs 3044 矩形面积求并

    Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21511   Accepted: 8110 Descrip ...

  4. codevs 3044 矩形面积求并 (扫描线)

    /* 之前一直偷懒离散化+暴力做着题 今天搞一下扫描线 自己按照线段树的一般写法写的有些问题 因为不用于以前的区间sum so 题解搬运者23333 Orz~ 去掉了打标记的过程 同时更新区间的时候先 ...

  5. codevs 3044 矩形面积求并 || hdu 1542

    这个线段树的作用其实是维护一组(1维 平面(?) 上的)线段覆盖的区域的总长度,支持加入/删除一条线段. 线段树只能维护整数下标,因此要离散化. 也可以理解为将每一条处理的线段分解为一些小线段,要求每 ...

  6. 【题解】codevs 3044 矩形面积合并

    传送门 3044 矩形面积求并 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 输入n个矩形,求他们总共占地面积(也就是求一下 ...

  7. [Codevs] 矩形面积求并

    http://codevs.cn/problem/3044/ 线段树扫描线矩形面积求并 基本思路就是将每个矩形的长(平行于x轴的边)投影到线段树上 下边+1,上边-1: 然后根据线段树的权值和与相邻两 ...

  8. [codevs3044][POJ1151]矩形面积求并

    [codevs3044][POJ1151]矩形面积求并 试题描述 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入 可能有多组数据,读到n=0为止(不超过15组) 每组数据第一行一个数n ...

  9. 矩形面积求并(codevs 3044)

    题目描述 Description 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入描述 Input Description 可能有多组数据,读到n=0为止(不超过15组) 每组数据第一行 ...

随机推荐

  1. android app性能优化大汇总(google官方Android性能优化典范 - 第1季)

    大多数用户感知到的卡顿等性能问题的最主要根源都是因为渲染性能.从设计师的角度,他们希望App能够有更多的动画,图片等时尚元素来实现流畅的用户体验.但是Android系统很有可能无法及时完成那些复杂的界 ...

  2. [转] 利用任务计划重启sqlserver服务

    1.建立一个批处理文件restartsqlserver.bat     内容如下:     net   stop   mssqlserver   /y    net   start  mssqlser ...

  3. CSS之侧边栏

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. win8升级win10后的windows.old怎么删除

    现在win10只是出了预览版本,还没有出正式版,但是相信一部分朋友都与小D一样,喜欢尝鲜,已上用上了win10了. 有些人是通过win8或是8.1直接安装升级上去的,这样操作是安装方便,但是系统会为了 ...

  5. 桌面虚拟化之部署DDC-5.6

    1. 打开管理软件 2. 选择桌面部署 3. 如果没有数据库则使用默认的 4. 导入许可证文件(当然未申请可试用30天) 5. 主机类型选择无(这里未做服务器虚拟化) 6. 最后完成初步配置 配置计算 ...

  6. 配置Hibernate二级缓存步骤

    配置Hibernate二级缓存步骤: 加入二级缓存的jar包及配置文件 jar包位置:hibernate-release-4.1.8.Final\lib\optional\ehcache下所有jar包 ...

  7. VmodCAM 初始化

    ; WIP Last Changed Rev: 2172 ;********************************************************************** ...

  8. WP开发笔记——不同Item显示不同ApplicationBar:适用于Pivot与Panorama

    一.在xaml页面定义两个ApplicationBar: <phone:PhoneApplicationPage.Resources> <shell:ApplicationBar I ...

  9. NSS_07 extjs中grid在工具条上的查询

    碰到的每个问题, 我都会记下走过的弯路,尽量回忆白天的开发过程, 尽量完整, 以使自己以后可以避开这些弯路. 这个问题在系统中应用得比较多, 在一个gridpanel的工具条上有俩搜索框, panel ...

  10. javascript中的光标

    最近项目中要做一个键盘操作,光标移动的功能:增强用户体验:问朋友查资料了解到这方面的知识:整理备忘: 1.IE使用textRange对象,其他使用selectionStart selectionEnd ...