codves 3044 矩形面積求並

2022-03-02 21:50:11 字數 1309 閱讀 5906

題目等級 : 鑽石 diamond

輸入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

線段樹+掃瞄線

本題解析參照黃學長部落格

#include#include

#include

using

namespace

std;

intn,opl,opr,flag;

int col[801

];double hash[201],sum[1601

],ans;

struct

node

e[202

];bool cmp(node a,node b)

inline

void up(int k,int l,int

r)inline

void change(int k,int l,int

r)

int m=l+r>>1

;

if(opl<=m) change(k<<1

,l,m);

if(opr>m) change((k<<1)+1,m+1

,r);

up(k,l,r);

}int

main()

sort(hash+1,hash+2*n+1

); sort(e+1,e+2*n+1

,cmp);

ans=0

;

for(int i=1;i<=2*n;i++)

printf(

"%.2lf\n

",ans);

}}

CODEVS 3044 矩形面積求並

描述 輸入n個矩形,求他們總共占地面積 也就是求一下面積的並 分析 其實上面的部落格講的講的就很清楚了.就相當於把矩形用許多小矩形來代替.這些小矩形都是有一邊或幾條邊延長後過其他矩形的頂點.這麼一說好像更複雜了.換個說法,就是把所有矩形的邊都作為可無限延長的分割線,將所有矩形分割成小矩形.每個小矩形...

CodeVS3044矩形面積求並

codevs3044矩形面積求並 題解 題目描述 description 輸入n個矩形,求他們總共占地面積 也就是求一下面積的並 輸入描述 input description 可能有多組資料,讀到n 0為止 不超過15組 每組資料第一行乙個數n,表示矩形個數 n 100 接下來n行每行4個實數x1,...

codevs3044 矩形面積求並

這幾天入了資料結構的坑,其實簡單的線段樹 樹狀陣列 左偏樹之類的以前就會的,但是不是很會應用,特別是例如優化dp 擴充套件到高維這些應用上就是渣啊,因為之前對離散化不了解,所以看了hwzer的 好久都沒懂,到最後發現原來這個線段樹維護的並不是乙個數軸,只是乙個陣列而已,乙個陣列有被標記的元素,然後用...