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

coreBugZJ

此 blog 已棄。

POJ 2528 Mayor's posters

  1/*
  2POJ 2528 Mayor's posters
  3
  4
  5----問題描述:
  6
  7The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim.
  8The city council has finally decided to build an electoral wall for placing the posters and introduce the following rules: 
  9Every candidate can place exactly one poster on the wall. 
 10All posters are of the same height equal to the height of the wall;
 11the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
 12The wall is divided into segments and the width of each segment is one byte.
 13Each poster must completely cover a contiguous number of wall segments.
 14
 15They have built a wall 10000000 bytes long (such that there is enough place for all candidates).
 16When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width.
 17Moreover, the candidates started placing their posters on wall segments already occupied by other posters.
 18Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
 19Your task is to find the number of visible posters when all the posters are placed given the information about posters' size,
 20their place and order of placement on the electoral wall.
 21
 22
 23----輸入:
 24
 25The first line of input contains a number c giving the number of cases that follow.
 26The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines describe the posters in the order in which they were placed. The i-th line among the n lines contains two integer numbers li and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= li <= ri <= 10000000. After the i-th poster is placed, it entirely covers all wall segments numbered li, li+1 , , ri.
 27
 28
 29----輸出:
 30
 31For each input data set print the number of visible posters after all the posters are placed.
 32
 33
 34----樣例輸入:
 35
 361
 375
 381 4
 392 6
 408 10
 413 4
 427 10
 43
 44
 45----樣例輸出:
 46
 474
 48
 49
 50----分析:
 51
 52線段樹。
 53
 54
 55*/

 56
 57
 58
 59#include <iostream>
 60#include <algorithm>
 61
 62using namespace std;
 63
 64template<unsigned int N>
 65class CSegTree
 66{
 67public : 
 68        void init( int b, int e ){
 69                init( 1, b, e );
 70        }

 71        void modify( int b, int e, int d ){
 72                begin = b;
 73                end   = e;
 74                data  = d;
 75                modify( 1 );
 76        }

 77        int query( void ){
 78                memset( visible, 0sizeof( visible ) );
 79                query( 1 );
 80                data = 0;
 81                forint i = 1; i < N; ++i ){
 82                        if( visible[ i ] ){
 83                                ++data;
 84                        }

 85                }

 86                return data;
 87        }

 88
 89private : 
 90        void init( int node, int b, int e ){
 91                left[ node ]  = b;
 92                right[ node ] = e;
 93                id[ node ]    = 0;
 94                if( b < e ){
 95                        init( node << 1, b, ( b + e ) >> 1 );
 96                        init( ( node << 1 ) + 1, ( ( b + e ) >> 1 ) + 1, e );
 97                }

 98        }

 99        void modify( int node ){
100                if( ( end < left[ node ] ) || ( right[ node ] < begin ) ){
101                        return;
102                }

103                if( data == id[ node ] ){
104                        return;
105                }

106                if( ( begin <= left[ node ] ) && ( right[ node ] <= end ) ){
107                        id[ node ] = data;
108                        return;
109                }

110                if( id[ node ] ){
111                        id[ node << 1 ] = id[ ( node << 1 ) + 1 ] = id[ node ];
112                        id[ node ] = 0;
113                }

114                modify( node << 1 );
115                modify( ( node << 1 ) + 1 );
116                if( id[ node << 1 ] == id[ ( node << 1 ) + 1 ] ){
117                        id[ node ] = id[ node << 1 ];
118                }

119        }

120        void query( int node ){
121                if( id[ node ] ){
122                        visible[ id[ node ] ] = true;
123                        return;
124                }

125                if( left[ node ] >= right[ node ] ){
126                        return;
127                }

128                query( node << 1 );
129                query( ( node << 1 ) + 1 );
130        }

131
132        enum{ L = N * 3 };
133        typedef int IA[ L ];
134        IA left, right, id;
135        bool visible[ N ];
136
137        int begin, end, data;
138        
139}
;
140
141template<unsigned int N, unsigned int NT>
142class CLine
143{
144public : 
145        friend istream & operator>>( istream & is, CLine<N,NT> & li ){
146                is >> li.n;
147                forint i = 1; i <= li.n; ++i ){
148                        is >> li.left[ i ] >> li.right[ i ];
149                }

150                return is;
151        }

152        void init_tree( CSegTree<NT> & tree ){
153                int i, j;
154                n2 = n << 1;
155                for( j = i = 1; i <= n; ++i,++j ){
156                        line[ j ].p     = left[ i ];
157                        line[ j ].id    = i;
158                        line[ j ].bLeft = true;
159
160                        ++j;
161                        line[ j ].p     = right[ i ];
162                        line[ j ].id    = i;
163                        line[ j ].bLeft = false;
164                }

165                sort( line + 1, line + n2 + 1 );
166                tp = 0;
167                line[ 0 ].p = -123456;
168                for( i = 1; i <= n2; ++i ){
169                        if( line[ i ].bLeft ){
170                                left[ line[ i ].id ] = ( line[ i - 1 ].p == line[ i ].p ? tp : ++tp );
171                        }

172                        else{
173                                right[ line[ i ].id ] = ( line[ i - 1 ].p == line[ i ].p ? tp : ++tp );
174                        }

175                }

176                tree.init( 1, tp );
177                for( i = 1; i <= n; ++i ){
178                        tree.modify( left[ i ], right[ i ], i );
179                }

180        }

181
182private : 
183        struct SLine
184        {
185                bool operator<const SLine & b ){
186                        return p < b.p;
187                }

188                int  p, id;
189                bool bLeft;
190        }
;
191        SLine  line[ N * 2 ];
192        int    left[ N ], right[ N ], n, n2, tp;
193}
;
194
195const int L = 30009, TL = L * 2;
196CSegTree<TL> tree;
197CLine<L,TL> line;
198
199int main(){
200        int td;
201        cin >> td;
202        while( td-- ){
203                cin >> line;
204                line.init_tree( tree );
205                cout << tree.query() << endl;
206        }

207        return 0;
208}

209

posted on 2012-04-22 22:50 coreBugZJ 閱讀(566) 評論(0)  編輯 收藏 引用 所屬分類: ACMAlgorithmDataStructure課內作業

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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久久精品国产91久久性色| 欧美成人在线免费视频| 欧美性猛交99久久久久99按摩| 久久久99国产精品免费| 欧美丝袜一区二区三区| 亚洲国产精品热久久| 狠狠入ady亚洲精品经典电影| 一本色道久久综合| 亚洲另类一区二区| 老色批av在线精品| 另类亚洲自拍| 精品电影一区| 久久精品在这里| 久久狠狠亚洲综合| 国产精品色网| 亚洲在线一区二区| 亚洲永久免费视频| 欧美日精品一区视频| 亚洲精选视频免费看| 一区二区不卡在线视频 午夜欧美不卡'| 久久狠狠亚洲综合| 久久亚洲精品欧美| 激情偷拍久久| 麻豆精品在线视频| 欧美国产精品劲爆| 亚洲精品美女在线观看播放| 欧美 日韩 国产在线| 欧美激情影院| 99精品99| 国产精品久久毛片a| 亚洲中字在线| 久久视频一区| 91久久精品国产91性色 | 欧美aa在线视频| 精品69视频一区二区三区| 久久精品一区中文字幕| 欧美va天堂| 亚洲三级免费电影| 欧美日韩国产一级| 亚洲一区综合| 老司机久久99久久精品播放免费| 激情五月综合色婷婷一区二区| 久久久亚洲影院你懂的| 欧美大胆a视频| 一二三区精品福利视频| 国产精品免费观看在线| 欧美一级在线视频| 欧美激情第8页| 亚洲一区在线免费| 国产偷国产偷精品高清尤物| 久久影视三级福利片| 亚洲精品美女| 久久精品72免费观看| 亚洲经典一区| 国产精品欧美精品| 久久综合伊人77777| 亚洲精品资源| 久久美女性网| 亚洲视频 欧洲视频| 国产主播一区二区| 欧美日本一道本| 欧美在线播放一区二区| 亚洲欧洲一区二区天堂久久| 欧美一区免费视频| 日韩亚洲国产欧美| 国产综合视频| 欧美日韩在线精品一区二区三区| 欧美中文字幕在线视频| 亚洲日本va午夜在线电影| 久久精品视频va| 一区二区三区黄色| 在线看视频不卡| 国产精品美女在线观看| 欧美国产国产综合| 久久国产精品久久久久久电车| 亚洲精品视频中文字幕| 久久综合久色欧美综合狠狠| 亚洲一区二区三区在线| 亚洲国产精品va在线观看黑人 | 欧美网站在线观看| 嫩草伊人久久精品少妇av杨幂| 亚洲视频一区二区免费在线观看| 欧美黄色成人网| 久久久噜噜噜久久人人看| 亚洲综合清纯丝袜自拍| 亚洲精品色图| 亚洲激情视频在线播放| 国产亚洲精品综合一区91| 欧美午夜在线视频| 欧美激情精品久久久久久久变态| 欧美在线视频日韩| 亚洲一区欧美激情| 一本一本a久久| 日韩视频精品在线观看| 亚洲国产另类精品专区| 欧美成人自拍视频| 欧美成人精品福利| 蜜桃av一区二区三区| 久久午夜精品| 久久九九免费| 久久久99国产精品免费| 久久精品一二三| 久久精品国产一区二区电影| 香蕉乱码成人久久天堂爱免费| 亚洲视频专区在线| 亚洲一区二区三区在线观看视频 | 亚洲国产精品va在线观看黑人| 国产综合久久久久久| 国产亚洲午夜| 一区二区视频在线观看| 狠狠综合久久| 亚洲电影有码| 日韩视频一区| 亚洲一区二区三区国产| 亚洲女人天堂av| 欧美在线高清视频| 久久综合久久综合久久| 欧美成va人片在线观看| 亚洲高清视频在线| 亚洲精品看片| 亚洲一区二区在线看| 性久久久久久| 老司机午夜精品| 欧美片第1页综合| 国产美女精品视频| 亚洲成在人线av| 一本不卡影院| 欧美一区二区视频97| 麻豆9191精品国产| 亚洲激情视频在线观看| 这里只有精品视频| 久久精品一区二区三区四区| 久久综合图片| 欧美视频久久| 激情成人中文字幕| 99视频日韩| 久久精品水蜜桃av综合天堂| 免费一级欧美片在线观看| 亚洲精品精选| 久久精品男女| 欧美日韩一区二区三| 国产在线国偷精品产拍免费yy| 91久久精品一区二区别| 亚洲欧美日韩第一区| 免费日韩一区二区| 亚洲视频在线观看| 蜜臀91精品一区二区三区| 国产精品a久久久久| 激情综合在线| 午夜精品久久久久久久男人的天堂| 久久久久久久久综合| 99国产精品久久久久久久| 欧美一级视频| 欧美日韩一区自拍| 亚洲国产裸拍裸体视频在线观看乱了中文 | 久久久国产午夜精品| 亚洲欧洲精品一区二区三区| 亚洲淫片在线视频| 欧美日产在线观看| 激情久久一区| 亚欧美中日韩视频| 亚洲人成小说网站色在线| 久久国产精品99国产精| 欧美三级第一页| 亚洲激情电影中文字幕| 久久久精品免费视频| 国产精品99久久久久久宅男 | 狠狠做深爱婷婷久久综合一区| 99re热精品| 亚洲第一偷拍| 久久视频一区二区| 国产一区二区高清| 欧美一区二区三区免费视| 亚洲精品中文字幕在线观看| 老牛嫩草一区二区三区日本| 国产日韩综合一区二区性色av| 亚洲午夜激情在线| 亚洲六月丁香色婷婷综合久久| 久久人人97超碰精品888| 国产视频精品xxxx| 性做久久久久久久免费看| 99热免费精品在线观看| 欧美精品日日鲁夜夜添| 亚洲日本中文字幕| 欧美激情亚洲国产| 嫩模写真一区二区三区三州| 在线观看欧美日韩| 久久综合久久久久88| 久久精彩免费视频| 国产亚洲欧美日韩精品| 久久国产婷婷国产香蕉| 欧美一区二区三区视频免费播放 | 午夜精品久久久久久久99樱桃 | 国产女精品视频网站免费| 午夜精品久久久久| 亚洲欧美精品伊人久久| 国产欧美精品久久| 久久精品免费电影| 久久精品视频网|