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

ACM___________________________

______________白白の屋
posts - 182, comments - 102, trackbacks - 0, articles - 0
<2010年10月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用鏈接

留言簿(24)

隨筆分類(332)

隨筆檔案(182)

FRIENDS

搜索

積分與排名

最新隨筆

最新評論

閱讀排行榜

評論排行榜

MiYu原創(chuàng), 轉(zhuǎn)帖請注明 : 轉(zhuǎn)載自 ______________白白の屋    

題目地址 :

http://poj.org/problem?id=2528

題目描述:

Mayor's posters
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 15722Accepted: 4444

Description

The 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. The city council has finally decided to build an electoral wall for placing the posters and introduce the following rules: 
  • Every candidate can place exactly one poster on the wall. 
  • All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown). 
  • The wall is divided into segments and the width of each segment is one byte. 
  • Each poster must completely cover a contiguous number of wall segments.

They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections. 
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall. 

Input

The first line of input contains a number c giving the number of cases that follow. The 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.

Output

For each input data set print the number of visible posters after all the posters are placed. 

The picture below illustrates the case of the sample input. 

Sample Input

1
5
1 4
2 6
8 10
3 4
7 10

Sample Output

4

 題目分析 :

代碼
/*
   線段樹 +  離散化
    
   好像記得暑假做 樹狀數(shù)組的時(shí)候 做過一個(gè)離散化的題目, 當(dāng)時(shí)是用2分查詢
   離散節(jié)點(diǎn)標(biāo)記的, 速度還是可以的, 不過那時(shí)對離散化也沒有什么概念, 大
   概是沒怎么接觸, 今天做了這道題目的時(shí)候,  也算是明白了 離散化 的基本
   意思,因?yàn)?nbsp;題目的 數(shù)據(jù)范圍很大 , 1- 10000000,直接線段樹的話, 先不說
   內(nèi)存會(huì)不會(huì)爆, 這么大的范圍估計(jì)也是 TLE了. 
   仔細(xì)讀題, 可以看到  1<= N <= 10000, 也就是說 最多只有 10000個(gè)點(diǎn), 如果
   每個(gè)點(diǎn)都不同, 那么最多也只有 20000 個(gè)數(shù)據(jù), 那么離散后的 范圍就相當(dāng)小;
   
   離散化 的大概思路 :   比如說給你一組 數(shù)據(jù) 1 4 1000 100000,  如果直接
                         開線段, 顯然是浪費(fèi), 那么我們只要 進(jìn)行 映射 :
                                1    1  
                                4    2
                             1000    3
                           100000    4
                         接下來 我們只要對 1 2 3 4 建立線段樹就行了 只需要
                         [1,4]的區(qū)間     
*/

/*
Mail to   : miyubai@gamil.com
Link      : 
http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu
Author By : MiYu
Test      : 1
Complier  : g++ mingw32-3.4.2
Program   : 2528
Doc Name  : Mayor's posters
*/
//#pragma warning( disable:4789 )
#include <iostream>
#include 
<fstream>
#include 
<sstream>
#include 
<algorithm>
#include 
<string>
#include 
<set>
#include 
<map>
#include 
<utility>
#include 
<queue>
#include 
<stack>
#include 
<list>
#include 
<vector>
#include 
<cstdio>
#include 
<cstdlib>
#include 
<cstring>
#include 
<cmath>
#include 
<ctime>
using namespace std;
int T, N, x, y;
map 
< intint > mp;
set <int> st;
map
<int,int>::iterator beg, end;
struct segtree {
       
int left, right,cov;
       
int mid () { return (left+right)>>1; }
}seg[
80010];
struct P {  //節(jié)點(diǎn)數(shù)據(jù) 
       int left, right;
}pp[
10010];
void creat ( int x, int y, int rt = 1 ) {
     seg[rt].left 
= x;
     seg[rt].right 
= y;
     seg[rt].cov 
= 0;
     
if ( x == y ) return ;
     
int mid = seg[rt].mid();
     creat ( x, mid, rt 
<< 1 );
     creat ( mid 
+ 1, y, rt << 1 | 1 );     
}
void insert ( int x, int y, int flag, int rt = 1 ) {
     
//如果線段被覆蓋, 直接標(biāo)記, 返回 
    if ( seg[rt].left == x && seg[rt].right == y ) {
        seg[rt].cov 
= flag;
        
return;   
    }    
    
int LL = rt << 1, RR = rt << 1 | 1, mid = seg[rt].mid();
    
if ( seg[rt].cov != -1 ) {  
       
//如果線段是被覆蓋的 , 標(biāo)記下傳, 同時(shí)自身標(biāo)記-1,表示有多個(gè)標(biāo)記 
        seg[LL].cov = seg[RR].cov = seg[rt].cov;
        seg[rt].cov 
= -1;   
    }
    
//遞歸 插入 
    if ( y <= mid ) insert ( x, y, flag, LL );
    
else if ( x > mid ) insert ( x, y, flag, RR );
    
else {
          insert ( x, mid, flag, LL );
          insert ( mid 
+ 1, y, flag, RR );     
    }
}
void query ( int x, int y, int rt = 1 ) {
    
// 線段被覆蓋 , 將覆蓋標(biāo)記 放入 set 
    if ( seg[rt].cov != -1 && seg[rt].left == x && seg[rt].right == y ) {
        st.insert ( seg[rt].cov );
        
return ;   
    }
else {//遞歸查詢 
          int LL = rt << 1, RR = rt << 1 | 1, mid = seg[rt].mid();
          
if ( y <= mid ) query ( x, y, rt << 1 ); 
          
else if ( x > mid ) query ( x, y, rt << 1 | 1 );
          
else {
                query ( x, mid, LL );
                query ( mid 
+ 1, y, RR );     
          }
    }
}
void print () {
     
for ( set<int>::iterator it = st.begin(); it != st.end(); ++ it )
           cout 
<< *it << endl;     
}
int main ()
{
    scanf ( 
"%d"&T );
    creat ( 
120010 );
    
while ( T -- ) {
           mp.clear();
           st.clear (); 
           scanf ( 
"%d"&N );
           
for ( int i = 1; i <= N; ++ i ) {
                scanf ( 
"%d%d"&pp[i].left, &pp[i].right );
                 
//map 去重 
                mp[pp[i].left] = 88; mp[pp[i].right] = 88;    
           }      
           beg 
= mp.begin(), end = mp.end();
           
//因?yàn)閙ap 已經(jīng)自動(dòng)排序了,所以直接從 1 --> N 開始標(biāo)記, 離散化 
           for ( int i = 1;beg != end; ++ beg, ++ i ) {         
                beg
->second = i;  
           }
           
//因?yàn)榫€段樹已經(jīng)建立好了, 所以沒必要每次都重建一次, 只要插入一條
           
//覆蓋所有區(qū)間的 底板 就行了 
           insert ( 1, N * 20 );
           
for ( int i = 1; i <= N; ++ i ) {
                
//用離散后的標(biāo)記 插入 線段 
                insert ( mp[pp[i].left], mp[pp[i].right], i );   
           }
           query ( 
1, N * 2 );
           
//print();
           int cnt = st.size();
           
if ( *st.begin() == 0 ) -- cnt; 
           printf ( 
"%d\n", cnt );
    }

    
return 0;
}

 

Feedback

# re: PKU 2528 POJ 2528 Mayor's posters ( 線段樹+離散化 ) ACM 2528 IN PKU  回復(fù)  更多評論   

2011-10-19 22:34 by wjjay
3
1 10
1 5
7 10
請問這組數(shù)據(jù)在你程序里跑出來的結(jié)果跟你手算的一樣么?
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一区二区三区www| 91久久黄色| 欧美四级在线| 久久午夜视频| 性xx色xx综合久久久xx| 日韩午夜在线电影| 亚洲第一福利视频| 久久久成人精品| 欧美一级久久久久久久大片| 99伊人成综合| 亚洲全部视频| 亚洲国产精品久久久久婷婷884| 国产精品制服诱惑| 国产精品麻豆va在线播放| 欧美日韩精品免费| 欧美国产一区二区| 欧美mv日韩mv国产网站app| 久久久久欧美精品| 久久国产精品久久国产精品| 亚洲制服欧美中文字幕中文字幕| 日韩午夜激情| 亚洲激情一区二区三区| 巨胸喷奶水www久久久免费动漫| 久久精品国产清自在天天线| 亚洲欧美日韩国产| 午夜视频一区二区| 午夜亚洲性色福利视频| 亚洲欧美激情一区| 午夜国产精品影院在线观看| 亚洲欧美网站| 欧美一区午夜精品| 欧美一区亚洲| 久久久人成影片一区二区三区| 羞羞漫画18久久大片| 欧美亚洲网站| 久久精品国产77777蜜臀| 久久久久久久综合日本| 久久亚洲欧美| 男女精品视频| 亚洲黄色av一区| 亚洲精品在线免费| 一区二区福利| 欧美亚洲色图校园春色| 久久嫩草精品久久久精品一| 免费看成人av| 欧美日韩国产色综合一二三四| 欧美三区在线| 国产欧美精品日韩| 国产一区二区精品久久| 亚洲国产成人av在线| 日韩视频―中文字幕| 亚洲一区尤物| 久久精品夜色噜噜亚洲aⅴ| 麻豆成人综合网| 亚洲人成免费| 亚洲欧美日韩在线观看a三区| 欧美一区二区在线免费播放| 美女视频网站黄色亚洲| 欧美片在线播放| 国产欧美精品一区二区三区介绍 | 国产精品综合av一区二区国产馆| 国产精品一区二区三区乱码| 狠狠色丁香久久婷婷综合_中| 91久久国产精品91久久性色| 亚洲亚洲精品三区日韩精品在线视频| 欧美一区2区三区4区公司二百| 蜜臀a∨国产成人精品| 日韩一级不卡| 久久久999精品| 欧美日韩精品一区二区天天拍小说 | 国产欧美 在线欧美| 亚洲高清在线精品| 亚洲一级特黄| 欧美freesex8一10精品| 国产精品99久久久久久人| 久久久99爱| 国产精品r级在线| ●精品国产综合乱码久久久久| 亚洲最黄网站| 久久天堂精品| 中文久久精品| 欧美成人一二三| 国产日韩视频| 99精品国产99久久久久久福利| 新狼窝色av性久久久久久| 欧美激情一区二区在线 | 欧美激情乱人伦| 国产欧美午夜| 亚洲小视频在线观看| 欧美 日韩 国产 一区| 亚洲欧美日韩另类精品一区二区三区| 欧美成年人在线观看| 国内精品视频在线观看| 亚洲专区一二三| 亚洲国产一区在线| 久久精品国产成人| 国产精品色婷婷| 一本色道久久综合精品竹菊| 免费av成人在线| 亚洲欧洲99久久| 国产精品国产自产拍高清av王其| 亚洲全部视频| 欧美freesex交免费视频| 香蕉久久夜色精品国产使用方法| 欧美日韩视频在线观看一区二区三区 | 欧美影院视频| 亚洲视频在线观看一区| 欧美久久久久久久久久| 亚洲精品免费一区二区三区| 久热精品在线视频| 久久成人久久爱| 国产日韩精品在线播放| 亚洲午夜久久久久久尤物| 91久久久国产精品| 欧美国产日韩一二三区| 最新成人av在线| 欧美激情视频一区二区三区不卡| 欧美一区免费| 国产一区二区三区久久悠悠色av| 午夜亚洲伦理| 亚洲欧美日韩中文播放| 国产日本欧美一区二区三区在线| 亚洲在线中文字幕| 中国亚洲黄色| 国产精品日韩精品欧美在线| 午夜亚洲性色视频| 亚洲在线成人| 国产欧美一区二区精品仙草咪 | 亚洲丰满少妇videoshd| 欧美成人午夜77777| 亚洲精品欧美极品| 亚洲啪啪91| 欧美三级电影网| 亚洲你懂的在线视频| 亚洲一区二区三区四区五区午夜| 国产精品电影观看| 欧美一进一出视频| 久久国产欧美日韩精品| 亚洲成人资源| 亚洲黑丝在线| 欧美日韩亚洲一区二区三区四区| 亚洲午夜精品网| 午夜精品视频在线观看一区二区| 国产亚洲a∨片在线观看| 久久婷婷国产综合精品青草| 久久久久久亚洲精品杨幂换脸| 亚洲国产老妈| 99精品国产福利在线观看免费| 欧美午夜久久久| 久久久99爱| 欧美高清视频| 亚洲男人的天堂在线观看| 亚洲欧美在线观看| 在线观看欧美视频| 亚洲国产成人精品女人久久久| 欧美日韩免费在线视频| 欧美在线看片| 欧美a一区二区| 亚洲欧美日韩在线| 久久久噜噜噜久噜久久| 亚洲毛片在线| 小黄鸭精品aⅴ导航网站入口| 在线播放日韩欧美| 日韩亚洲成人av在线| 国产一区二区日韩精品| 91久久精品国产| 国产农村妇女精品一区二区| 欧美好骚综合网| 国产精品美女www爽爽爽视频| 久久―日本道色综合久久| 欧美sm视频| 欧美在线影院| 欧美激情91| 久久看片网站| 欧美日韩精品一区| 噜噜噜躁狠狠躁狠狠精品视频| 欧美精品一区二区三区久久久竹菊| 午夜精品久久久久久久99黑人| 蜜臀av性久久久久蜜臀aⅴ四虎| 午夜亚洲视频| 欧美激情在线有限公司| 久久久欧美精品sm网站| 国产精品theporn| 亚洲高清色综合| 国产亚洲免费的视频看| 亚洲乱码一区二区| 亚洲电影免费观看高清| 亚洲特级片在线| 99在线|亚洲一区二区| 久久精品国产2020观看福利| 亚洲一区二区三区视频播放| 免费在线观看一区二区| 久久青草福利网站| 国产精品日韩欧美一区二区| 亚洲激情一区| 亚洲国产精品电影| 欧美一区二区日韩一区二区| 亚洲一级免费视频| 欧美日韩第一区| 亚洲成色精品|