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

ACM___________________________

______________白白の屋
posts - 182, comments - 102, trackbacks - 0, articles - 0
<2011年10月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

常用鏈接

留言簿(24)

隨筆分類(332)

隨筆檔案(182)

FRIENDS

搜索

積分與排名

最新隨筆

最新評論

閱讀排行榜

評論排行榜

MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋    

題目地址 :

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

 題目分析 :

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

/*
Mail to   : miyubai@gamil.com
Link      : 
http://www.cnblogs.com/MiYu  || http://m.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 {  //節點數據 
       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 ) {
     
//如果線段被覆蓋, 直接標記, 返回 
    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 ) {  
       
//如果線段是被覆蓋的 , 標記下傳, 同時自身標記-1,表示有多個標記 
        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 ) {
    
// 線段被覆蓋 , 將覆蓋標記 放入 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();
           
//因為map 已經自動排序了,所以直接從 1 --> N 開始標記, 離散化 
           for ( int i = 1;beg != end; ++ beg, ++ i ) {         
                beg
->second = i;  
           }
           
//因為線段樹已經建立好了, 所以沒必要每次都重建一次, 只要插入一條
           
//覆蓋所有區間的 底板 就行了 
           insert ( 1, N * 20 );
           
for ( int i = 1; i <= N; ++ i ) {
                
//用離散后的標記 插入 線段 
                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  回復  更多評論   

2011-10-19 22:34 by wjjay
3
1 10
1 5
7 10
請問這組數據在你程序里跑出來的結果跟你手算的一樣么?
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久久久久综合网天天| 99xxxx成人网| 国产精品久久久久婷婷| 欧美精品999| 欧美成人高清| 欧美国产一区视频在线观看| 久久久久欧美| 麻豆av福利av久久av| 久久一区二区三区四区| 玖玖精品视频| 欧美激情精品久久久久| 久久99伊人| 久久婷婷国产综合国色天香| 久久免费99精品久久久久久| 欧美不卡视频| 欧美日韩在线播放三区四区| 国产精品swag| 国产综合av| 亚洲福利免费| 中文高清一区| 久久精品99国产精品酒店日本| 久久全国免费视频| 美日韩精品视频免费看| 亚洲国产综合91精品麻豆| 欧美激情视频在线免费观看 欧美视频免费一| 欧美**人妖| 一区二区三区久久网| 久久精品道一区二区三区| 美女脱光内衣内裤视频久久网站| 欧美激情一区二区三区四区| 国产精品女人久久久久久| 国产亚洲福利一区| 亚洲欧洲精品成人久久奇米网| 亚洲一级黄色片| 久久亚洲不卡| 一区二区国产精品| 久久男人资源视频| 国产精品高潮视频| 亚洲国产va精品久久久不卡综合| 亚洲一区二区在线免费观看视频| 久久国产一区| 亚洲人成人一区二区三区| 亚洲欧美日韩网| 欧美日本免费| 影音先锋另类| 久久国产主播精品| 国产精品99久久久久久久久| 午夜国产精品视频免费体验区| 欧美成人免费一级人片100| 国产日韩欧美高清| 一区二区三区国产精华| 免播放器亚洲一区| 亚洲欧美国产一区二区三区| 欧美成人午夜免费视在线看片| 国产欧美va欧美va香蕉在| 亚洲久久视频| 一区二区欧美日韩| 久久综合电影| 国产视频在线一区二区| 欧美亚洲一区二区在线观看| 一本色道**综合亚洲精品蜜桃冫| 免费看的黄色欧美网站| 精品88久久久久88久久久| 欧美一区二区黄色| 亚洲午夜久久久久久久久电影网| 欧美精品七区| 99视频日韩| 亚洲美女性视频| 欧美日本高清视频| 99天天综合性| 日韩视频在线观看一区二区| 欧美国产日韩一区二区三区| 亚洲精品国精品久久99热一| 欧美护士18xxxxhd| 欧美91精品| 91久久精品美女高潮| 亚洲高清激情| 欧美精品乱码久久久久久按摩| 亚洲欧洲精品成人久久奇米网| 你懂的视频一区二区| 亚洲欧美日韩国产中文| 国产精品九九久久久久久久| 午夜精品福利在线| 欧美亚洲三区| 亚洲高清不卡在线| 亚洲欧洲精品一区二区三区波多野1战4 | 一区二区三区欧美| 亚洲精品中文字幕女同| 欧美午夜激情在线| 性做久久久久久免费观看欧美| 午夜免费电影一区在线观看| 激情六月综合| 亚洲精品女av网站| 欧美人妖另类| 欧美在线视频全部完| 久久久一区二区| 日韩视频在线一区二区| 中文无字幕一区二区三区| 国产欧美日韩精品专区| 欧美gay视频激情| 欧美精品在线免费观看| 欧美一级网站| 欧美尤物巨大精品爽| 亚洲精品久久久久| 亚洲视频香蕉人妖| 红桃视频国产精品| 亚洲美女视频网| 狠狠噜噜久久| 亚洲精美视频| 国内精品模特av私拍在线观看| 亚洲国产一区二区在线| 国产无一区二区| 99av国产精品欲麻豆| 在线精品国精品国产尤物884a| 在线亚洲伦理| 中文一区在线| 国产精品99久久久久久久久| 欧美日韩免费观看一区=区三区| 亚洲一区精品视频| 久久精品综合| 性做久久久久久久久| 欧美成人乱码一区二区三区| 欧美一区二区三区四区夜夜大片 | 久久综合九色综合久99| 欧美劲爆第一页| 久久欧美中文字幕| 国产三级欧美三级日产三级99| 日韩视频免费| 一区二区三区精密机械公司 | 玖玖玖免费嫩草在线影院一区| 久久电影一区| 国产精品一页| 亚洲欧美日韩精品久久亚洲区| 亚洲综合色激情五月| 欧美图区在线视频| 一区二区三区久久精品| 亚洲一级电影| 国产精品无码专区在线观看| 亚洲性视频网址| 欧美一区免费| 韩日成人av| 农村妇女精品| 亚洲九九爱视频| 亚洲特黄一级片| 国产精品高潮呻吟久久| 亚洲在线免费| 久久久亚洲精品一区二区三区| 国产精品亚洲精品| 亚洲欧美国产高清va在线播| 亚洲一区在线观看免费观看电影高清| 欧美激情亚洲综合一区| 亚洲欧洲综合| 久久久久久夜| 激情综合久久| 久久精品日产第一区二区三区| 欧美—级a级欧美特级ar全黄| 亚洲精品九九| 一本色道久久综合亚洲精品按摩 | 久久久久国产精品麻豆ai换脸| 久久精品成人| 国内久久精品视频| 欧美bbbxxxxx| 牛牛精品成人免费视频| 亚洲第一页在线| 免费精品视频| 一区二区日韩| 久久国产婷婷国产香蕉| 国产欧美一区二区三区沐欲| 午夜精品在线看| 亚洲一区尤物| 国产精一区二区三区| 欧美在线观看一区二区| 久久久久久免费| 韩国成人福利片在线播放| 亚洲欧美资源在线| 欧美高清在线一区二区| 亚洲高清不卡| 亚洲欧美激情精品一区二区| 国产综合久久| 久久国产日本精品| 麻豆国产精品一区二区三区 | 亚洲国产成人porn| 欧美一二三视频| 禁久久精品乱码| 欧美精品一区二区在线观看| 一区二区高清| 亚洲午夜精品17c| 激情久久久久久久| 欧美精品亚洲精品| 午夜一级久久| 欧美顶级艳妇交换群宴| 一区二区三区在线视频观看| 国产精品第一区| 久久性天堂网| 亚洲主播在线| 亚洲一二三级电影| 欧美成人一区在线| 午夜视频一区二区| 91久久精品国产91久久性色| 欧美va亚洲va香蕉在线|