• <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>
            posts - 101,  comments - 57,  trackbacks - 0
                   這是一題相當有水平的并查集問題。雖然我一次性ac,但是基本上是沒有任何思路搜索了一下牛人思路才過的。

                   思考這題時,我陷入到了以下怪圈:
            1.并查集應該是無限的,但是貌似這題的并集只有三個
            2.當兩者關系未被確認是哪個集合時,會出現無限多的臨時子集
            3.如何表示臨時子集
              
                   看了看牛人的思路,相當巧妙:并查集基本還是無限集,有限集用關系向量來表示。
            1.使用關系向量的方法,讓我獲益匪淺。
            2.計算關系向量的方法,又如此的巧合。
            3.并查集并不一定是相同的才并一起,又回歸到第一點,當關系向量可以用有限集表示時,并查集里的元素可以不是同一類元素。

            最后還要說,這題相當牛B.
            #include "stdio.h"

            #define MAX 50001

            #define Similar 0   
            #define Enemy   1
            #define Food    2
            //  Food eat Enemy
            //  Enemy eat Similar
            //  Similar eat Food

            struct _xtree
            {
                
            int parent;
                
            int relation;
            }
            xtree[MAX];

            int N, K;

            void build()
            {
                
            int i;
                
            for (i = 1; i <= N; i++)
                
            {
                    xtree[i].parent   
            = i;
                    xtree[i].relation 
            = Similar;
                }

            }


            int find(int i)
            {
                
            int p = xtree[i].parent;
                
            if (p != i)
                
            {
                    xtree[i].parent   
            = find(xtree[i].parent);
                    xtree[i].relation 
            = (xtree[p].relation + xtree[i].relation) % 3;
                }


                
            return xtree[i].parent;
            }


            int check(int x, int y, int r)
            {
                
            int root_x, root_y, root_r;

                
            if (x > N || y > N)
                
            {
                    
            return 0;
                }


                root_x 
            = find(x);
                root_y 
            = find(y);
                
                
            if (root_x == root_y)  // x relate y
                {        
                    
            return (xtree[x].relation - xtree[y].relation + 3% 3  == r ? 1 : 0;          
                }

                
            else
                
            {
                    root_r 
            =  (xtree[y].relation + r + (3 - xtree[x].relation)) % 3;
                    xtree[root_x].parent   
            = root_y;
                    xtree[root_x].relation 
            = root_r;
                    
            return 1;
                }

            }


            void main()
            {
                
            int op, x, y;
                
            int count = 0;

                scanf(
            "%d %d"&N, &K);

                build();

                
            while (K--)
                
            {
                    scanf(
            "%d %d %d"&op, &x, &y);
                   
                    
            if (!check(x, y, op == 1 ? Similar : Enemy))
                    
            {
                        count
            ++;
                    }
                        
                }

                printf(
            "%d\n", count);
            }


            posted on 2010-08-28 21:11 margin 閱讀(160) 評論(0)  編輯 收藏 引用
            <2009年5月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿

            隨筆檔案

            文章分類

            文章檔案

            收藏夾

            常去的壇子

            • CVC電腦病毒論壇
            • 很多人說我是AV,我告訴他們:別瞧不起人,我們也能創造價值
            • 安全焦點
            • 黑客聚集的地方,一般是好酒最多的地方...
            • 看雪論壇
            • 國內最強的加密解密論壇,成醉其中經常夜不歸宿
            • 驅動開發論壇
            • 厭倦了啤的朋友們,來我們來整點白的...痛痛快快的BSOD也好過隔鞋瘙癢!

            我的朋友

            • Sen的blog
            • IDE方面資深的受害者...經常為一個變量的定義找不著北的痛苦程序員(深表同情)
            • 老羅的blog
            • 良師益友,千年水牛,引擎猛男,分析怪獸,墨鏡酷哥,臺球高手....

            搜索

            •  

            最新評論

            久久99精品国产麻豆宅宅| 久久精品人人做人人妻人人玩| 国产精品美女久久久久久2018| 久久婷婷五月综合国产尤物app| 久久这里的只有是精品23| 久久精品国产欧美日韩99热| 日产精品久久久久久久性色| 狠狠色丁香婷综合久久| 日韩十八禁一区二区久久| 亚洲AV无码久久| 久久噜噜电影你懂的| 精品国产热久久久福利| av色综合久久天堂av色综合在| 国产午夜电影久久| 四虎国产精品成人免费久久| 久久精品中文騷妇女内射| 久久久久久青草大香综合精品| 色综合久久无码中文字幕| 久久免费国产精品| 精品国际久久久久999波多野| 久久久久女教师免费一区| 久久精品国产只有精品2020| 久久亚洲精品国产精品婷婷 | 久久伊人亚洲AV无码网站| 99久久免费国产精品特黄| 99久久亚洲综合精品网站| 色诱久久久久综合网ywww| 一本久久综合亚洲鲁鲁五月天| 国产2021久久精品| 久久91精品国产91久久小草| 国产精品成人久久久| 亚洲性久久久影院| 久久综合伊人77777| 国产精品九九久久免费视频 | 久久久久久精品久久久久| 色婷婷综合久久久久中文字幕| 精品久久一区二区三区| 精品久久8x国产免费观看| 日韩人妻无码一区二区三区久久| 香蕉久久夜色精品国产尤物| 久久99精品国产99久久6|