青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設(shè)計空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

Picture
Time Limit:2000MS? Memory Limit:10000K
Total Submit:742 Accepted:411

Description
A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. Their sides are all vertical or horizontal. Each rectangle can be partially or totally covered by the others. The length of the boundary of the union of all rectangles is called the perimeter.

Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.


The corresponding boundary is the whole set of line segments drawn in Figure 2.

The vertices of all rectangles have integer coordinates.

Input
Your program is to read from standard input. The first line contains the number of rectangles pasted on the wall. In each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. The values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate.

0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.

Output
Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.

Sample Input

7
-15 0 5 10
-5 8 20 25
15 -4 24 14
0 -6 16 4
2 15 10 22
30 10 36 20
34 0 40 16

Sample Output

228

Source
IOI 1998

做這道題之前我用線段樹的結(jié)構(gòu)過了幾個題目 效果沒有我想象的好
但是這道題明顯就出了差距 直接離散化與用線段樹來做效果差了有將近10倍!




線段樹的基本應(yīng)用:請參考這篇文章

http://m.shnenglu.com/sicheng/archive/2006/11/24/15640.html

這里我們再加上測度與連續(xù)段的作用:

(一)、?? 測度

由于線段樹結(jié)構(gòu)遞歸定義,其測度也可以遞歸定義。增加數(shù)據(jù)域 Lines_Tree.M 表示以該結(jié)點為根的子樹的測度。 M 取值如下:

?

?

???????? a[j] – a[i] ?? 該結(jié)點 Count>0

M? =??? 0???????? ? 該結(jié)點為葉結(jié)點且 Count=0

???????? Leftchild .M + Rightchild .M ? 該結(jié)點為內(nèi)部結(jié)點且 Count=0

?

據(jù)此,可以用 Lines_Tree.UpData 來動態(tài)地維護 Lines_Tree.M UpData 在每一次執(zhí)行 Insert Delete 之后執(zhí)行。定義如下:

Procedure? Lines_Tree.UpData

1??????? if? count? >? 0

2??????? ??then? M? ? ? a[j]? ? [i]????? { 蓋滿區(qū)間,測度為 a[j] – a[i]}

3??????? ??else? if? j? -? i? =? 1 ????????{ 是否葉結(jié)點 }

4??????? ??????????then? M? ? ? 0 ??????{ 該結(jié)點是葉結(jié)點 }

5??????? ??????????else? M? ? ? Leftchild .M? +? Rightchild .M
????????????????????????????????????????? ?{
內(nèi)部結(jié)點 }

UpData 的復(fù)雜度為 O(1) ,則用 UpData 來動態(tài)維護測度后執(zhí)行根結(jié)點的 Insert Delete 的復(fù)雜度仍為 O(logN)

(二)、?? 連續(xù)段數(shù)

這里的連續(xù)段數(shù)指的是區(qū)間的并可以分解為多少個獨立的區(qū)間。如 [1 2] [23] [5 6] 可以分解為兩個區(qū)間 [1 3] [5 6] ,則連續(xù)段數(shù)為 2 。增加一個數(shù)據(jù)域 Lines_Tree.line 表示該結(jié)點的連續(xù)段數(shù)。 Line 的討論比較復(fù)雜,內(nèi)部結(jié)點不能簡單地將左右孩子的 Line 相加。所以再增加 Lines_Tree.lbd Lines_Tree.rbd 域。定義如下:

?

???????? 1??? 左端點 I 被描述區(qū)間蓋到

lbd? =?

???????? 0? ?? 左端點 I 不被描述區(qū)間蓋到

?

???????? 1???? 右端點 J 被描述區(qū)間蓋到

rbd? =?

??????? ?0 ???? 右端點 J 不被描述區(qū)間蓋到

?

lbd rbd 的實現(xiàn):

????????? 1? 該結(jié)點 count > 0

lbd? =??? 0? 該結(jié)點是葉結(jié)點且 count = 0

????????? leftchild .lbd??? 該結(jié)點是內(nèi)部結(jié)點且 Count=0

? ????????1? 該結(jié)點 count > 0

rbd? =??? 0? 該結(jié)點是葉結(jié)點且 count = 0

????????? rightchild .rbd?? 該結(jié)點是內(nèi)部結(jié)點且 Count=0

有了 lbd rbd Line 域就可以定義了:

??????? 1? 該結(jié)點 count > 0

Line =?? 0? 該結(jié)點是葉結(jié)點且 count = 0

??????? ?Leftchild .Line? +? Rightchild .Line? -? 1
????????
當(dāng)該結(jié)點是內(nèi)部結(jié)點且 Count=0 Leftchild .rbd = 1 Rightchild .lbd = 1

???????? Leftchild .Line? +? Rightchild .Line??
??? ?????
當(dāng)該結(jié)點是內(nèi)部結(jié)點且 Count=0 Leftchild .rbd Rightchild .lbd 不都為 1

?

據(jù)此,可以定義 UpData’ 動態(tài)地維護 Line 域。與 UpData 相似, UpData’ 也在每一次執(zhí)行 Insert Delete 后執(zhí)行。定義如下:

Procedure? Lines_Tree.UpData’

1??????? if? count? >? 0 ??????????{ 是否蓋滿結(jié)點表示的區(qū)間 }

2??????? ??then? lbd?? ? ? 1

3??????? ???????rbd?? ? ? 1

4??????? ???????Line? ? ? 1

5??????? ??else? if? ?j? -? i? =? 1???? { 是否為葉結(jié)點 }

6??????? ??????????then? lbd?? ? ? 0?? { 進行到這一步,如果為葉結(jié)點,
??????????????????????????????????????????????? count = 0}

7??????? ????????????????rbd? ? ? 0

8??????? ????????????????line? ? ? 0

9??????? ??????????else? line? ? ?? Leftchild .line? +? Rightchild .line? -?

????????????????????????????? Leftchild .rbd * Rightchild .lbd

{ 用乘法確定 Leftchild .rbd Rightchild .lbd 是否同時為 1}

?

于是我按下面的步驟重寫了程序:

1.??????? 以矩形頂點坐標(biāo)切割平面,實現(xiàn)橫縱坐標(biāo)的離散化并建立映射 X_Map Y_Map

2.??????? 事件排序

3.??????? Root.Build(1, N*2)

4.??????? Nowm??? ? ? 0

5.??????? NowLine? ? ? 0

6.??????? Ans????? ? ? 0

7.??????? for?? I? ? ? 1? to? 事件的最大編號

8.??????? ??do?? if? I 是插入事件

9.??????? ??????????then? Root.Insert(Y_Map.Coord[ 事件線段頂點 1]
???????????????????????? Y_Map.Coord[
事件線段頂點 2])

10.??? ??????????else? Root.Delete(Y_Map.Coord[ 事件線段頂點 1]
?????????????????? ? ??????Y_Map.Coord[
事件線段頂點 2])

11.??? ????????nowM??? ? ? Root.M

12.??? ????????nowLine? ? ? Root.Line

13.??? ????? ???ans??? ? ? ans? +? lastLine * 2 * (X_Map[I] – Y_Map[I-1])

14.??? ????????ans????? ? ? ans? +? |nowM – lastM|

15.??? ????????lasM???? ? ? nowM

16.??? ????????lastLine?? ? ? nowLine

參考論文《IOI98試題PICTURE談起 陳宏

#include? < stdio.h >
#include?
< stdlib.h >

const ? int ?maxn? = ? 5010 ;
// 寫一個線段樹的過程
struct ?Lines_tree
{
????Lines_tree?
* ?lchild,? * ?rchild;
????
int ?m;? // 測度
???? int ?cnt;??? // count
???? int ?lines;? // 連續(xù)段數(shù)
???? int ?lbd,?rbd;? // 左右端點是否被覆蓋?
???? int ?f,?r;? // 左右端點
}
;
Lines_tree
* ?root;
struct ?rec { int ?x,?y,?x1,?y1;} r[maxn];
struct ?Line
{
????
int ?x,?y1,?y2; int ?sign;
????Line(
int ?a,? int ?b,? int ?c, int ?d):x(a),?y1(b),?y2(c),?sign(d) {}
????Line(
void ):x( 0 ),y1( 0 ),y2( 0 ),sign( 0 ) {} ?
}
line[ 2 * maxn + 10 ];
int ?nr;
int ?ans;

void ?make_tree( int ?a,? int ?b,?Lines_tree * ?node)
{
????node
-> lines? = ? 0 ;?node -> m? = ? 0 ;?node -> cnt? = ? 0 ;
????node?
-> ?lbd? = ? 0 ;?node? -> ?rbd? = ? 0 ;
????node
-> lchild? = ?NULL;?node -> rchild? = ?NULL;
????node
-> f? = ?a;?node -> r? = ?b;
????
if (b - a > 1 )
????
{
????????node
-> lchild? = ? new ?Lines_tree;
????????make_tree(a,?(a
+ b) / 2 ,?node -> lchild);
????????node
-> rchild? = ? new ?Lines_tree;
????????make_tree((a
+ b) / 2 ,?b,?node -> rchild);
????}

}


void ?make( int ?a,? int ?b)
{
?????root?
= ? new ?Lines_tree;
?????make_tree(a,?b,?root);
}


void ?update(Lines_tree? * ?now)??? // lbd,?rbd,?m的計算都在這個里面!
{
????
if (now -> cnt > 0 )?now -> m? = ?now -> r - now -> f;
????
else ? if (now -> r == now -> f + 1 )?now -> m? = ? 0 ;
????
else ?now -> m? = ?now -> lchild -> m? + ?now -> rchild -> m;
}


void ?update2(Lines_tree * ?now)
{
????
if (now -> cnt > 0 )? {?now -> lbd? = ? 1 ;?now -> rbd? = ? 1 ;?now -> lines? = ? 1 ;?}
????
else ? if (now -> f + 1 == now -> r)? {now -> lbd? = ? 0 ;?now -> rbd? = ? 0 ;?now -> lines? = ? 0 ;}
????
else
????
{
????????now
-> lbd? = ?now -> lchild -> lbd;?now -> rbd? = ?now -> rchild -> rbd;
????????now
-> lines? = ?now -> lchild -> lines + now -> rchild -> lines? - ?now -> lchild -> rbd * now -> rchild -> lbd;
????}

}


void ?insert( int ?a,? int ?b,?Lines_tree? * ?now)
{
????
if (a <= now -> f? && ?b >= now -> r)
????????now
-> cnt ++ ;
????
if (now -> r - now -> f > 1 )
????
{
????????
if (a < (now -> f + now -> r) / 2 )????insert(a,?b,?now -> lchild);
????????
if (b > (now -> f + now -> r) / 2 )????insert(a,?b,?now -> rchild);
????}

????update(now);
????update2(now);
}


void ?del( int ?a,? int ?b,?Lines_tree? * ?now)
{
????
if (a <= now -> f? && ?b >= now -> f)
????
{
????????
if (a == now -> f)?now -> lbd? = ? 0 ;
????????
if (b == now -> r)?now -> rbd? = ? 0 ;
????????now
-> cnt -- ;
????}

????
if (now -> r - now -> f > 1 )
????
{
????????
if (a < (now -> f + now -> r) / 2 )????del(a,?b,?now -> lchild);
????????
if (b > (now -> f + now -> r) / 2 )????del(a,?b,?now -> rchild);
????}

????update(now);
????update2(now);
}


int ?cmp( const ? void ? * ?a,? const ? void ? * ?b)
{
????
return ?( * (Line * )a).x? - ?( * (Line * )b).x;??? // 這里不要寫成->
}


void ?init()
{
????
// initiation
????
// input
???? int ?i;
????scanf(
" %d " ,? & nr);
????
for (i = 0 ;?i < nr;?i ++ )
????
{
????????scanf(
" %d%d%d%d " ,? & r[i].x,? & r[i].y,? & r[i].x1,? & r[i].y1);
????????line[
2 * i]? = ?Line(r[i].x,?r[i].y,?r[i].y1,? 0 );
????????line[
2 * i + 1 ]? = ?Line(r[i].x1,?r[i].y,?r[i].y1,? 1 );
????}
????????
????qsort(line,?nr
* 2 ,? sizeof (line[ 0 ]),?cmp);
????
// pretreatment
}


void ?work()
{
????
int ?nowM? = ? 0 ;
????
int ?nowLine? = ? 0 ;
????
int ?lastM? = ? 0 ;
????
int ?lastLine? = ? 0 ;
????
int ?i;
????
for (i = 0 ;?i < nr * 2 ;?i ++ )
????
{
????????
if (line[i].sign == 0 )
????????????insert(line[i].y1,?line[i].y2,?root);
????????
else ?del(line[i].y1,?line[i].y2,?root);
????????nowM?
= ?root -> m;
????????nowLine?
= ?root -> lines;
????????ans?
+= ?lastLine? * ? 2 ? * ?(line[i].x - line[i - 1 ].x);
????????ans?
+= ?abs(nowM - lastM);
????????lastM?
= ?nowM;
????????lastLine?
= ?nowLine;
????}

}


void ?output()
{
????printf(
" %d\n " ,?ans);
}


int ?main()
{
// ????freopen("t.in",?"r",?stdin);
????make( - 10000 ,? 10000 );
????init();
????work();
????output();
????
return ? 0 ;
}

Feedback

# re: 線段樹測度與連續(xù)斷的應(yīng)用 on IOI98 pictures  回復(fù)  更多評論   

2007-04-07 01:01 by
void del( int a, int b, Lines_tree * now)
{
if (a <= now -> f && b >= now -> f)


這個是不是有問題?

只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲二区视频在线| 91久久中文| 国产日韩欧美| 亚洲综合第一页| 欧美日韩一区二区国产| 亚洲国产另类久久精品| 女女同性精品视频| 久久久国产精品亚洲一区| 国内成人在线| 亚洲欧洲在线免费| 欧美激情aⅴ一区二区三区| 一区二区视频免费完整版观看| 久久夜色精品国产欧美乱| 久久精品国产久精国产一老狼 | 亚洲黑丝在线| 欧美日韩在线三区| 久久国产精品久久w女人spa| 久久久久在线观看| 亚洲天堂av高清| 久久精品人人做人人综合| 亚洲精品网站在线播放gif| 亚洲视频www| 亚洲高清免费| 亚洲欧美日本日韩| 亚洲精品久久视频| 欧美中文字幕久久| 免费在线欧美视频| 亚洲欧美影院| 欧美成人精品三级在线观看| 欧美在线黄色| 国产精品久久久久久久久借妻 | 亚洲欧洲一区二区三区在线观看| 亚洲精品视频在线播放| 国内精品久久久久伊人av| 中文国产成人精品| 中文亚洲免费| 欧美无乱码久久久免费午夜一区 | 欧美高清视频免费观看| 玖玖综合伊人| 影音先锋国产精品| 久久久综合网站| 美女脱光内衣内裤视频久久影院| 国产欧美一区二区精品婷婷| 亚洲欧美国产高清| 久久只有精品| 最近中文字幕日韩精品| 欧美成人精品在线观看| 欧美福利视频一区| 亚洲自拍偷拍一区| 国产视频自拍一区| 久热精品在线视频| 亚洲人成艺术| 亚久久调教视频| 国内综合精品午夜久久资源| 亚洲欧美一区二区在线观看| 国产精品大片免费观看| 销魂美女一区二区三区视频在线| 国产日韩av高清| 久久成人资源| 亚洲精品一区二| 久久久亚洲影院你懂的| 日韩视频免费观看高清在线视频 | 亚洲国产精品久久久久婷婷884 | 日韩一级不卡| 国产亚洲精品v| 欧美日韩你懂的| 久久成人免费日本黄色| 99国产麻豆精品| 亚洲福利视频免费观看| 亚洲欧洲精品成人久久奇米网| 欧美搞黄网站| 久久久999| 欧美亚洲在线观看| 99精品国产一区二区青青牛奶| 老司机67194精品线观看| 中国av一区| 亚洲女同精品视频| 久久精品一区二区三区中文字幕| 国产麻豆精品视频| 毛片基地黄久久久久久天堂| 欧美在线在线| 久久久久久久久一区二区| 黄色成人精品网站| 好吊一区二区三区| 国语自产精品视频在线看8查询8| 国产区日韩欧美| 韩国精品久久久999| 黄色成人在线免费| 亚洲国产精品成人一区二区| 亚洲精品自在久久| 亚洲女ⅴideoshd黑人| 性做久久久久久久免费看| 久久精品中文字幕一区| 国产欧美一区二区三区在线老狼 | 日韩午夜中文字幕| 一区二区三区日韩欧美| 欧美一级大片在线免费观看| 久久久久亚洲综合| 亚洲黑丝在线| 亚洲欧美在线x视频| 久久久国产一区二区| 欧美日韩色婷婷| 一区二区三区在线高清| 亚洲最新中文字幕| 欧美激情导航| 欧美在线免费看| 国产精品久久久久毛片大屁完整版 | 欧美激情aⅴ一区二区三区| 欧美一级黄色网| 亚洲精品一区中文| 久久先锋影音av| 国语自产精品视频在线看| 久久性天堂网| 国产精品欧美精品| 野花国产精品入口| 亚洲国产精品久久久久| 久久国产精品一区二区| 国产精品裸体一区二区三区| 99热这里只有成人精品国产| 你懂的网址国产 欧美| 久久激情网站| 黑人极品videos精品欧美裸| 欧美在线亚洲综合一区| 午夜精品久久久久久久99黑人| 欧美精品一区三区| 欧美顶级少妇做爰| 亚洲美女视频网| 亚洲激情在线观看| 欧美日韩一区二区三区在线观看免| 亚洲精选国产| 亚洲午夜激情免费视频| 国产精品初高中精品久久| 午夜亚洲一区| 久久se精品一区精品二区| 国内精品视频在线观看| 久久久久九九九| 久久夜色精品国产噜噜av| 亚洲精品色婷婷福利天堂| 91久久精品国产91性色 | 免费久久久一本精品久久区| 日韩午夜电影在线观看| 在线一区二区视频| 亚洲国产成人av| 亚洲另类春色国产| 国模套图日韩精品一区二区| 欧美国产一区视频在线观看| 欧美日韩在线播| 美女视频一区免费观看| 欧美午夜精品久久久久免费视| 久久不射2019中文字幕| 久久这里只精品最新地址| 欧美福利视频| 欧美高清视频免费观看| 国产午夜精品美女毛片视频| 亚洲破处大片| 国产日韩视频| 夜久久久久久| 亚洲国产精品激情在线观看| 午夜精品久久久久久久久久久久久 | 欧美国产精品中文字幕| 午夜久久久久久| 欧美日韩综合不卡| 日韩一二三区视频| 亚洲视频axxx| 国产精品乱人伦一区二区 | 欧美福利电影网| 亚洲视频综合在线| 亚洲精品国产精品国自产观看浪潮| 国产精品网站在线观看| 亚洲精品日韩综合观看成人91| 亚洲欧洲精品一区二区精品久久久 | 亚洲一区成人| 欧美视频不卡| 亚洲一级黄色| 久久久久久9| 亚洲国产精品t66y| 欧美国产精品日韩| 在线视频亚洲一区| 欧美精选午夜久久久乱码6080| 欧美福利视频| 亚洲一区二区三区精品在线观看 | 国产亚洲精品高潮| 午夜精品一区二区三区在线| 久久免费视频在线| 一区二区三区**美女毛片 | 欧美色视频在线| 欧美一区午夜精品| 最新日韩精品| 久久九九99视频| 在线亚洲欧美| 激情视频一区| 国产美女扒开尿口久久久| 久久一区二区三区四区| 亚洲午夜极品| 亚洲欧洲日韩综合二区| 久久精彩免费视频| 亚洲欧美电影在线观看| 中文日韩在线视频| 亚洲日韩成人| 亚洲黄网站在线观看|