题目描述 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. log4Net 简单配置实用

    <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigu ...

  2. 集合框架学习之Collection和Map详解

    线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构.这些类均在java.util包中.本文试图通过简单的描述,向读者阐述各个类的作用以 ...

  3. Cocos2d-JS内置粒子系统

    从类图中我们可以看到,Cocos2d-JS中有内置的11种粒子,这些粒子的属性都是预先定义好的,我们也可以在程序代码中单独修改某些属性,我们在上一节的实例中都已经实现了这些属性的设置.内置粒子系统内置 ...

  4. UI5_UIAlertView与UIActionSheet

    // // ViewController.h // UI5_UIAlertView与UIActionSheet // // Created by zhangxueming on 15/7/7. // ...

  5. ESB数据发布思路

    通过esb已经将数据采集进数据库,现在需要开放一个接口,接受请求参数,进而通过参数进行数据查询,返回一段json格式的数据. ▼流程图: 刚开始尝试了很多个版本,可能是esb开发工具还用不熟练的原因吧 ...

  6. 8款给力HTML5/CSS3应用插件 可爱的HTML5笑脸

    1.HTML5/CSS3实现笑脸动画 非常可爱 今天我们要分享一款基于纯CSS3实现的笑脸动画,我们只要在面部滑动鼠标,即可让人物的眼睛嘴巴动起来,实现微笑的效果,还挺可爱的. 在线演示 源码下载 2 ...

  7. hdu 1284 钱币兑换问题 完全背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 递推公式:dp[i] = sum(dp[i], dp[i-C]) /* 钱币兑换问题 Time ...

  8. 济南学习 Day 3 T1 pm

    巧克力棒(chocolate)Time Limit:1000ms Memory Limit:64MB题目描述LYK 找到了一根巧克力棒,但是这根巧克力棒太长了,LYK 无法一口吞进去.具体地,这根巧克 ...

  9. DataGrid1

    2013-09-2512:26:31 1.DataGrid页面 <asp:DataGrid ID="msgInfo1" PageSize="8" Auto ...

  10. mysql颠覆实战笔记(五)--商品系统设计(二):定时更新商品总点击量

    继续回到沈老师的MYSQL颠覆实战,首先回顾下上一节课的内容,请大家会看下上节课写的存储过程. 打开prod_clicklog表, 我们只要把日期(不含时分秒)的部分存在数据库中, 如果同一日期有相同 ...