• <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
            非常感謝大牛的共享 。。。  回復  更多評論
              
            久久综合亚洲色HEZYO国产| 国产精品99久久久久久人| 久久不见久久见免费影院www日本| 99久久精品毛片免费播放| 一本大道加勒比久久综合| 日韩欧美亚洲综合久久影院Ds | 91麻豆国产精品91久久久| 亚洲va久久久噜噜噜久久男同 | 性做久久久久久久久久久| 久久亚洲AV无码精品色午夜| 久久精品aⅴ无码中文字字幕不卡| 久久精品亚洲福利| 97久久精品国产精品青草| 亚洲欧美日韩精品久久亚洲区| 久久精品国产亚洲AV无码偷窥| 午夜精品久久久久成人| 免费国产99久久久香蕉| 国产激情久久久久久熟女老人| 伊人久久免费视频| 久久精品国产久精国产思思| 一本色综合久久| 无码8090精品久久一区| 久久精品国产一区二区电影| 69国产成人综合久久精品| 婷婷久久久亚洲欧洲日产国码AV| 久久av高潮av无码av喷吹| 久久精品国产影库免费看| …久久精品99久久香蕉国产| 麻豆亚洲AV永久无码精品久久| 久久这里只有精品首页| 久久免费看黄a级毛片| 四虎国产精品成人免费久久| AAA级久久久精品无码区| 嫩草影院久久99| 久久高清一级毛片| 久久中文字幕视频、最近更新| 欧美综合天天夜夜久久| AAA级久久久精品无码区| 久久国产乱子伦精品免费午夜| 久久久久黑人强伦姧人妻| 久久天天躁狠狠躁夜夜不卡|