• <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 閱讀(528) 評論(1)  編輯 收藏 引用 所屬分類: 數據結構

            評論:
            # re: Zoj 1610 Count the Colors[未登錄] 2009-04-07 19:49 | wolf
            非常感謝大牛的共享 。。。  回復  更多評論
              
            久久精品黄AA片一区二区三区| 91精品国产91热久久久久福利 | 97久久超碰成人精品网站| 亚洲国产精品无码成人片久久| 少妇久久久久久久久久| 久久精品国产一区| 色悠久久久久久久综合网| 午夜天堂精品久久久久| 91精品观看91久久久久久| 漂亮人妻被中出中文字幕久久| 97久久国产亚洲精品超碰热| 亚洲另类欧美综合久久图片区| 久久久精品人妻一区二区三区蜜桃| 久久99国产精品99久久| 久久久久久国产精品免费免费| 午夜人妻久久久久久久久| 狠狠久久综合| 久久精品国产网红主播| 一级做a爰片久久毛片免费陪| 69国产成人综合久久精品| 女同久久| 久久久国产精华液| 久久精品国产精品国产精品污| 久久精品国产日本波多野结衣| 久久久无码精品亚洲日韩软件| 久久久国产精品福利免费| 久久久老熟女一区二区三区| 中文字幕精品无码久久久久久3D日动漫 | 久久99精品久久久久久| 久久久精品国产sm调教网站 | 久久综合综合久久97色| 久久亚洲精品成人AV| 国产亚洲美女精品久久久2020| 久久亚洲2019中文字幕| 日韩亚洲欧美久久久www综合网| 国产午夜福利精品久久2021| 色欲久久久天天天综合网| 久久精品一区二区三区AV| 久久无码AV中文出轨人妻| 精品伊人久久久| 中文字幕久久精品无码|