• <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
            非常感謝大牛的共享 。。。  回復  更多評論
              
            热综合一本伊人久久精品| 色偷偷久久一区二区三区| 日产精品久久久久久久| 2021国产精品久久精品| 色狠狠久久综合网| 久久久午夜精品| 久久人人爽人人爽人人片av麻烦 | 国产精品无码久久四虎| 久久综合欧美成人| 久久精品国产亚洲麻豆| 久久综合中文字幕| 香蕉久久影院| 亚洲精品无码久久久久| 成人久久久观看免费毛片| 久久青青草原综合伊人| 国产成人精品久久| 亚洲欧美日韩久久精品| 亚洲女久久久噜噜噜熟女| 国产成人精品免费久久久久| 久久精品草草草| 日本欧美国产精品第一页久久| 97视频久久久| 99久久无色码中文字幕| 9999国产精品欧美久久久久久| 亚洲另类欧美综合久久图片区| 日韩人妻无码精品久久久不卡| 日本精品久久久久中文字幕8| 亚洲AⅤ优女AV综合久久久| 亚洲AV无码久久精品蜜桃| 国产福利电影一区二区三区,免费久久久久久久精 | 性欧美大战久久久久久久久| 久久福利青草精品资源站免费| 久久乐国产精品亚洲综合| 久久精品国产亚洲AV无码娇色| 久久国产精品免费一区| 中文精品久久久久人妻不卡| 青青草国产精品久久久久| 中文字幕热久久久久久久| 大美女久久久久久j久久| 精品久久8x国产免费观看| 亚洲精品无码久久久久AV麻豆|