• <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)  編輯 收藏 引用 所屬分類: 數據結構

            評論:
            # re: Zoj 1610 Count the Colors[未登錄] 2009-04-07 19:49 | wolf
            非常感謝大牛的共享 。。。  回復  更多評論
              
            97久久超碰国产精品2021| 精品久久人人妻人人做精品 | 亚洲欧美另类日本久久国产真实乱对白 | 国产精品久久99| 久久精品中文字幕有码| 久久天天躁夜夜躁狠狠| 无码人妻少妇久久中文字幕蜜桃| 99久久无码一区人妻a黑| 久久久久国色AV免费看图片| 精品久久久久久无码专区| 久久99精品国产麻豆蜜芽| 久久精品国产亚洲AV不卡| 青青草国产成人久久91网| 久久久久久久精品成人热色戒| 国产精品久久久久9999高清| 久久久久亚洲av综合波多野结衣| 久久精品国产一区| 蜜臀久久99精品久久久久久小说| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 国产成人香蕉久久久久| 久久精品九九亚洲精品| 久久综合色之久久综合| 精品国产福利久久久| 久久久噜噜噜久久熟女AA片| 亚洲精品97久久中文字幕无码| 91久久精品国产91性色也| 精品无码久久久久久午夜| 亚洲AV无码1区2区久久| 久久九九兔免费精品6| 亚洲精品乱码久久久久久蜜桃| 国产一区二区三区久久| 国内精品久久人妻互换| A级毛片无码久久精品免费| 精品国产日韩久久亚洲| 热综合一本伊人久久精品 | 久久婷婷综合中文字幕| 久久se精品一区精品二区| 久久天堂电影网| 久久九色综合九色99伊人| 国产精品99久久久久久www| 国产亚洲色婷婷久久99精品91|