• <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>

            c++實(shí)例研究

            從0開始

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              104 隨筆 :: 0 文章 :: 20 評論 :: 0 Trackbacks
            開始沒想到用離散化,對線段樹也只在標(biāo)記線段,而無法想到著色的巧妙方法。本題關(guān)鍵在于對已經(jīng)著色線段內(nèi)的子線段著色時(shí),需要將此線段的顏色先下沉到孩子結(jié)點(diǎn)再著色,另一個(gè)要點(diǎn)便是查詢時(shí)遇到有色線段直接返回遞歸。這點(diǎn)注意到了,結(jié)果在代碼里沒有體現(xiàn),出現(xiàn)了好幾次莫名的WA。

            開始入門的時(shí)候很艱難,對代碼細(xì)節(jié)很難把握,并且時(shí)間一長,查錯(cuò)也變的很困難了。

            well 最后采用從AC代碼改回我代碼的方法值得在無法解決問題時(shí)使用
            less well 基本功還需要加強(qiáng),特別是細(xì)節(jié),一定不能忽視。

            /*  
            *    Doc Name: Mayor's posters
            *    Prob Id: 2528
            *    Serial Id: 1
            *    Author: LTE
            *    Date: 10/10/25
            */


            #include 
            <iostream>
            #include 
            <algorithm>
            using namespace std;
            int i,j,k;

            int a[10001],b[10001];
            int map[20002];
            int f[10000001];
            int nc,ns;
            bool color[10002];
            int cnt;
            struct Node
            {
                
            int l,r,mid,c;
            }
            ;
            Node tree[
            10001*10];

            int cmp(const void* a, const void *b)
            {
                
            return *(int*)a < *(int*)b;
            }


            void buildTree(const int l, const int r, const int pos)
            {   
                tree[pos].l 
            = l;
                tree[pos].r 
            = r;
                tree[pos].c 
            = 0;
                tree[pos].mid 
            = (l+r)>>1;
                
            if(l==r-1return;
                buildTree(l, tree[pos].mid, pos
            <<1);
                buildTree(tree[pos].mid, r, pos
            <<1|1);
            }


            void insert(const int pos, const int l, const int r, const int c)
            {
                
            if(l==tree[pos].l && r== tree[pos].r)
                
            {
                    tree[pos].c 
            = c;
                    
            return;
                }

                
                
            if(tree[pos].c > 0)
                
            {
                    tree[pos
            <<1].c = tree[pos<<1|1].c = tree[pos].c;
                    tree[pos].c 
            = 0;
                }


                
            if(r<=tree[pos].mid)
                
            {
                    insert(pos
            <<1, l, r, c);
                }

                
            else if(l>=tree[pos].mid)
                
            {
                    insert(pos
            <<1|1, l, r, c);
                }

                
            else
                
            {
                    insert(pos
            <<1, l, tree[pos].mid, c);
                    insert(pos
            <<1|1, tree[pos].mid, r, c);
                }

            }


            void query(int pos)
            {
                
            if(tree[pos].c)
                
            {
                    
            if(color[tree[pos].c]==false)
                    
            {
                        cnt
            ++;
                        color[tree[pos].c] 
            = true;
                    }

                    
            return;
                }

                
            if(tree[pos].l == tree[pos].r - 1)
                    
            return;
                query(pos
            <<1);
                query(pos
            <<1|1);
            }


            int main()
            {
                
            //!! delete while submit!!!
                
            //freopen("in.txt", "r", stdin);
                
            //freopen("out.txt", "w", stdout);

                scanf(
            "%d"&nc);
                
            while(nc--)
                
            {
                    scanf(
            "%d"&ns);
                    
            for(i=0; i<ns; ++i)
                    
            {
                        scanf(
            "%d%d"&a[i], &b[i]);
                        a[i]
            --;
                        map[i
            <<1= a[i];
                        map[i
            <<1|1= b[i];
                    }

                    sort(map, map
            +(ns<<1));
                    j
            =1;
                    f[map[
            0]]=j;
                    
            for(i=1; i<(ns<<1); i++)
                    
            {
                        
            if(map[i]!=map[i-1]) f[map[i]]=++j;    
                    }

                    buildTree(
            1, j, 1);
                    
            for(i=0; i<ns; ++i)
                    
            {
                        insert(
            1, f[a[i]], f[b[i]], i+1);
                    }

                    memset(color, 
            0sizeof(color));
                    cnt 
            = 0;
                    query(
            1);
                    printf(
            "%d\n", cnt);
                }

                
            return 0;
            }
            posted on 2010-10-25 21:57 elprup 閱讀(332) 評論(0)  編輯 收藏 引用 所屬分類: POJ
            亚洲人成网亚洲欧洲无码久久| 少妇久久久久久被弄到高潮| 国产成人精品三上悠亚久久| 久久99热这里只有精品国产| 久久久久亚洲av无码专区导航| 精品视频久久久久| 久久免费看黄a级毛片| 久久99国产精一区二区三区| 久久久WWW成人免费毛片| 久久久久国产精品嫩草影院| 99久久综合狠狠综合久久| 亚洲精品国产美女久久久| 狠狠色综合久久久久尤物| 69SEX久久精品国产麻豆| 久久久久99这里有精品10| 久久国产成人精品麻豆| 亚洲国产另类久久久精品小说 | 精品国产综合区久久久久久| 久久久国产视频| 国产精品久久久99| www.久久热.com| 伊人久久无码中文字幕| 久久人妻少妇嫩草AV无码蜜桃| 国产国产成人精品久久| 久久人人爽人人爽人人片AV不| 久久精品国产只有精品66| 久久精品国产99久久久香蕉| 国产精品一久久香蕉国产线看| 久久只有这精品99| 一本久久综合亚洲鲁鲁五月天| 久久高清一级毛片| 欧美一区二区精品久久| 大伊人青草狠狠久久| 久久久精品2019免费观看| 老色鬼久久亚洲AV综合| 久久精品国产99久久久古代| 99久久这里只精品国产免费| 性高朝久久久久久久久久| 国产精品久久久久久久app| 久久精品极品盛宴观看| 亚洲色大成网站www久久九|