• <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>
            #include? < stdio.h >
            #include?
            < stdlib.h >
            #include?
            < string .h >

            #define ?NOC?-1
            #define ?MUC?-2
            #define ?N???8001
            #define ?M???10000

            struct ??Node
            {
            ????
            int ??leftvalue;
            ????
            int ??rightvalue;
            ????
            int ??colour;
            ????
            ????Node
            * ??leftchild;
            ????Node
            * ??rightchild;
            }
            ;
            int ???colour[M];

            Node
            * ?create(?Node * ?r,? int ?left,? int ?right?)
            {????
            ????Node
            * ?temp = ? new ?Node;
            ????
            ????temp
            -> leftvalue = ?left;
            ????temp
            -> rightvalue = ?right;
            ????temp
            -> colour = ?NOC;
            ????
            ????temp
            -> rightchild = ?NULL;
            ????temp
            -> leftchild = ?NULL;
            ????????
            ????
            if ?(?right - ?left == ? 1 ?)? return ?temp;
            ????
            else {?
            ????????temp
            -> leftchild = ?create(?temp -> leftchild,?left,?(left + ?right) / ? 2 ?);
            ????????temp
            -> rightchild = ?create(?temp -> rightchild,?(left + right) / ? 2 ,?right?);
            ????}

            ????
            ????
            return ?temp;
            }
            ???????

            void ?insert(?Node * ?tree,? int ?left,? int ?right,? int ?c?)
            {
            ????
            int ?middle = ?(?tree -> leftvalue + ?tree -> rightvalue?) / ? 2 ;
            ????
            ????
            if ?(?right == ?tree -> rightvalue? && ?left == ?tree -> leftvalue? || ?tree -> colour == ?c)
            ????
            {
            ????????tree
            -> colour = ??c;
            ????????
            return ;
            ????}
            ???
            ????
            ????
            if ?(?tree -> colour? >= ? 0 ?)
            ????
            {
            ????????tree
            -> leftchild -> colour = ?tree -> colour;
            ????????tree
            -> rightchild -> colour = ?tree -> colour;
            ????}
            ????
            ????????
            ????tree
            -> colour = ?MUC;
            ????
            if ?(?middle >= ?right?)???????insert(?tree -> leftchild,?left,?right,?c?);
            ????
            else ?? if ?(?middle <= ?left?)??insert(?tree -> rightchild,?left,?right,c?);
            ????
            else
            ????
            {???
            ????????insert(?tree
            -> leftchild,?left,?middle,?c?);
            ????????insert(?tree
            -> rightchild,?middle,?right,?c?);
            ????}
            ????
            ???????
            }
            ?

            void ?getcolour(?Node * ?tree,? int & ?col?)
            {
            ????
            if ?(?tree -> colour >= ? 0 ? && ?tree -> colour != ?col?)
            ????
            {
            ????????col
            = ?tree -> colour;
            ????????colour[?tree
            -> colour?] ++ ;
            ????}
            ????
            ????
            else ? if ?(?tree -> colour == ?MUC?)
            ????
            {
            ????????getcolour(?tree
            -> leftchild,?col?);
            ????????getcolour(?tree
            -> rightchild,?col?);
            ????}

            ????
            else ?col = ?tree -> colour;???
            }
            ??????????????
            ????????????
            int ?main()
            {
            ????Node
            * ?root;
            ????
            int ???n;
            ????
            ????
            while (?scanf( " %d " , & n) != ?EOF?)
            ????
            {
            ????????root
            = ?create(?root,? 0 ,?N?);
            ????????
            int ??a,?b,?c;
            ????????
            for ?(? int ?i = ? 0 ;?i < ?n;? ++ i?)
            ????????
            {
            ????????????scanf(
            " %d%d%d " , & a, & b, & c);
            ????????????insert(?root,?a,?b,?c?);
            ????????}

            ????????
            ????????memset(?colour,?
            0 ,? sizeof (colour)?);
            ????????
            int ?col = ? - 1 ;
            ????????getcolour(?root,?col?);
            ????????
            ????????
            for ?(? int ?i = ? 0 ;?i < ?M;? ++ i?)?
            ??????????
            if ?(?colour[i]?)?printf( " %d?%d\n " ,?i,?colour[i]?);???
            ????????printf(
            " \n " );????
            ????}
            ????
            ????
            ????
            return ? 0 ;
            }
            ????????
            posted on 2008-10-08 14:29 Darren 閱讀(536) 評論(1)  編輯 收藏 引用 所屬分類: 數(shù)據(jù)結(jié)構(gòu)

            評論:
            # re: Zoj 1610 Count the Colors[未登錄] 2009-04-07 19:49 | wolf
            非常感謝大牛的共享 。。。  回復  更多評論
              
            一本色道久久88综合日韩精品| 精品久久亚洲中文无码| 日韩精品久久久久久免费| 久久夜色精品国产噜噜亚洲a| 一本大道久久a久久精品综合| 国产成人精品久久一区二区三区| 一本久久知道综合久久| 久久久久亚洲av综合波多野结衣| 青青热久久国产久精品| 色综合久久天天综线观看| 色综合久久久久综合99| 久久综合亚洲色HEZYO国产| 欧美久久亚洲精品| 亚洲欧洲精品成人久久曰影片| 日韩AV毛片精品久久久| 久久热这里只有精品在线观看| 一本色道久久综合狠狠躁| 人妻精品久久久久中文字幕69| 成人久久精品一区二区三区| 亚洲国产精品久久久久婷婷老年 | 国产精品久久久久免费a∨| 思思久久好好热精品国产| 久久精品国产免费观看三人同眠| 无码专区久久综合久中文字幕| 成人国内精品久久久久影院| 国产AV影片久久久久久| 国产精品久久久久蜜芽| 97久久超碰成人精品网站| 久久精品夜色噜噜亚洲A∨| 一本色道久久99一综合| 97久久精品人人澡人人爽| 久久无码专区国产精品发布| 夜夜亚洲天天久久| 亚洲va国产va天堂va久久| 国产视频久久| 九九久久自然熟的香蕉图片| 久久精品女人天堂AV麻| 国内精品久久久人妻中文字幕| 亚洲精品NV久久久久久久久久 | 精品久久久久久国产免费了| 亚洲午夜无码AV毛片久久|