hdu 1542 Atlantis 矩形面積並

2022-09-17 13:45:15 字數 1629 閱讀 7262

總的思路是

用線段樹維護線段長度

線段長度*h計算面積

具體操作看**

因為x太大還有離散化一下

學到了好多新姿勢

看discuss可能是後台資料有問題 資料要開到1000才能過

1 #include2

#define cl(a,b) memset(a,b,sizeof(a))

3#define debug(x) cerr<<#x<<"=="<<(x)<4

using

namespace

std;

5 typedef long

long

ll;6

7const

int maxn = 1000+10;8

9int rm[maxn<<1],col[maxn<<1],add[maxn<<1

];10

double x[maxn<<1],sum[maxn<<1

];11

12struct

line

1317 line(double x1,double x2,double _h,int

d):l(x1),r(x2),h(_h),kind(d){}

18 friend bool

operator

<(line p,line q)

19

22};

2324 line line[maxn<<1

];25

26void pushup(int l,int r,int

rt)27

32else

if(l==r)

33

36else

37 40}

4142

void update(int l,int r,int c,int l,int r,int

rt)43

50int m=l+r>>1;51

if( l <= m ) update(l,r,c,l,m,rt<<1

);52

if (r > m) update(l,r,c,m+1,r,rt<<1|1

);53

pushup(l,r,rt);54}

5556

intmain()

5772 sort(line,line+cnt);

73int cntx=0;74

for(auto i:px)

7578

double ans=0

;79 cl(add,0),cl(sum,0

);80

for(int i=0;i//

找到每一條線段 並更新

8187 printf("

test case #%d\n

",cas++);

88 printf("

total explored area: %.2f\n\n

",ans);89}

90return0;

91 }/*

9293294

10 10 20 20

9515 15 25 25.5960

9798

*/

HDU 1542 Atlantis 線段樹 掃瞄線

題意 求二維座標下n個矩陣的面積並 分析 如何求矩陣並的面積呢?如下圖 我們可以利用掃瞄線來做,什麼是掃瞄線?你可以把這些矩陣合併後看做乙個容器 現在你要把這些容器注滿水 很明顯 水先充滿的地方為 更據這樣的思想就可以把原圖分為下面幾個部分惹 那麼如何用 實現呢?我們需要乙個seg結構體儲存x方向線...

hdu 1542 Atlantis(求矩形面積並)

分別記錄x座標和y座標,將其分別按照從左到有的方向排序。然後對於乙個輸入的矩形的x,y座標範圍內的下標進行標記。以兩個相鄰的座標為最小單位分割圖形,最後求總面積。include include include define n 205 int mark n n double a n b n stru...

面積並問題 HDU 1542 Atlantis

hdu 1542 傳送門 題目大意就是幾個矩形相交,然後求出總的覆蓋面積,覆蓋多次的按一次算。典型的面積並問題。大體思路 記錄所給的點,排序,去掉重複的點,對點編號,可以理解成存放點的陣列的下表即為編號。對y軸建立線段樹,利用線段樹計算面積。ac code 1 include 2 include 3...