• <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>

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數據加載中……

            HDU 2818 Building Block 并查集

            這題算是半道水題了。但代碼實現還是有點麻煩,所以還是值得一寫。
            同一堆的方塊位于同一個集合。
            每個方塊保存一個值:距離底部的高度
            作為集合根部節點的方塊保存一個值:這堆方塊的高度
            在并查集的合并以及查找過程中需要維護這兩個值。

            #include <stdio.h>

            #define N 65536

            int P, parent[N], pos[N], top[N], stk[N];

            int fs(int idx)
            {
                
            int i;

                
            for (i = 0; parent[idx] != idx; i++{
                    stk[i] 
            = idx;
                    idx 
            = parent[idx];
                }


                
            for (i--; i >= 0; i--{
                    pos[stk[i]] 
            += pos[parent[stk[i]]];
                    parent[stk[i]] 
            = idx;
                }


                
            return idx;
            }


            int main()
            {
                
            char op[16];
                
            int x, y, rx, ry;

                
            for (x = 0; x < N; x++{
                    top[x] 
            = 1;
                    parent[x] 
            = x;
                }


                scanf(
            "%d"&P);
                
            while (P--{
                    scanf(
            "%s", op);
                    
            if (*op == 'M'{
                        scanf(
            "%d%d"&x, &y);
                        rx 
            = fs(x);
                        ry 
            = fs(y);
                        
            if (rx != ry) {
                            parent[rx] 
            = ry;
                            pos[rx] 
            = top[ry];
                            top[ry] 
            += top[rx];
                        }

                    }
             else {
                        scanf(
            "%d"&x);
                        fs(x);
                        printf(
            "%d\n", pos[x]);
                    }

                }

                
                
            return 0;
            }

            posted on 2010-10-25 21:50 糯米 閱讀(543) 評論(0)  編輯 收藏 引用

            久久无码国产| 亚洲国产精品无码久久98| 91精品国产色综久久 | 99久久婷婷国产一区二区| 精品熟女少妇aⅴ免费久久| 模特私拍国产精品久久| 国产精品久久久福利| 久久精品国产欧美日韩| 色婷婷综合久久久久中文一区二区| 久久久久免费看成人影片| 99久久国产主播综合精品| 性做久久久久久久久浪潮| 久久99精品国产99久久6男男| 色欲综合久久躁天天躁| 久久久久夜夜夜精品国产| 亚洲国产另类久久久精品黑人 | 久久无码高潮喷水| 99久久国产综合精品五月天喷水| 东方aⅴ免费观看久久av | 国产精品99久久久精品无码| 九九久久精品无码专区| 久久精品99久久香蕉国产色戒| 日日狠狠久久偷偷色综合免费 | 中文字幕乱码人妻无码久久| 久久亚洲国产成人精品无码区| 97超级碰碰碰久久久久| 99久久久国产精品免费无卡顿| 成人综合久久精品色婷婷| 亚洲欧美日韩久久精品 | 亚洲精品无码成人片久久| 日本久久中文字幕| 久久精品国产黑森林| 色综合久久精品中文字幕首页| 久久精品毛片免费观看| 国产综合久久久久| 久久99久久99精品免视看动漫| 色狠狠久久AV五月综合| 久久久一本精品99久久精品88| 久久精品中文无码资源站| 久久夜色精品国产噜噜亚洲AV| 中文字幕日本人妻久久久免费 |