• <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
            數據加載中……

            POJ 2492 A Bug's Life 并查集

            思路:

            這題的背景是亮點,描述如下:
            Background 
            Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
            Problem 
            Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.

            Hopper 在研究某種稀有蟲子的性行為。他假設蟲子們有兩種不同的性別,而且它們只跟異性發生關系。
            在他的試驗里,每個蟲子和它的性行為都很容易辨認,因為它們的背后印著號碼。
            給出一些蟲子的性行為,確定是否有同性戀的蟲子能推翻這個假設。

            同性戀確實讓人無法接受,無論是人還是蟲子。。

            這題的解法不是亮點,就是普通的并查集,數據量非常龐大,需要路徑壓縮。

            #include <stdio.h>
            #include 
            <string.h>

            int N, T, set[2048], val[2048];

            inline 
            int find(int idx)
            {
                
            static int stk[2048], i;

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

                
            for (i--; i >= 0; i--{
                    val[stk[i]] 
            ^= val[set[stk[i]]];
                    
            set[stk[i]] = idx;
                }


                
            return idx;
            }


            int main()
            {
                
            int i, j, a, b, t, m, r;

                scanf(
            "%d"&T);
                
            for (t = 1; t <= T; t++{
                    scanf(
            "%d%d"&N, &m);
                    memset(
            set0, (N + 1* 4);
                    memset(val, 
            0, (N + 1* 4);
                    r 
            = 0;
                    
            while (m--{
                        scanf(
            "%d%d"&a, &b);
                        i 
            = find(a);
                        j 
            = find(b);
                        
            if (i == j) 
                            r 
            |= val[a] == val[b];
                        
            else {
                            
            set[i] = b;
                            val[i] 
            = !val[a];
                        }

                    }

                    printf(
            "Scenario #%d:\n%s\n\n"
                            t,
                            r 
            ? "Suspicious bugs found!" : "No suspicious bugs found!"
                            );
                }


                
            return 0;
            }

            posted on 2010-04-17 20:57 糯米 閱讀(743) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            亚洲综合伊人久久综合| 久久久久久国产精品美女| 久久久久亚洲av综合波多野结衣 | 久久五月精品中文字幕| 性做久久久久久久久久久| 久久久久久免费视频| 精品国产VA久久久久久久冰 | 97久久国产露脸精品国产| 久久综合给久久狠狠97色| 国产91久久综合| 久久精品人人做人人爽电影| 久久久久久夜精品精品免费啦| 国内精品伊人久久久久影院对白| 欧美久久久久久| 亚洲国产成人久久精品动漫| 一本色道久久综合狠狠躁| 亚洲午夜精品久久久久久人妖| 国产成人无码精品久久久性色 | 18禁黄久久久AAA片| 国产精品久久国产精麻豆99网站| 久久国产视屏| 国产成人久久精品激情| 亚洲欧美日韩久久精品第一区| 国产成人综合久久久久久| 久久精品亚洲中文字幕无码麻豆 | AV无码久久久久不卡蜜桃| 怡红院日本一道日本久久 | 久久精品国产网红主播| 四虎影视久久久免费| 久久涩综合| 亚洲精品tv久久久久| 久久久久亚洲?V成人无码| 99久久精品九九亚洲精品| 久久亚洲高清观看| 国内精品久久久久| 久久国产精品无码一区二区三区| 国产69精品久久久久久人妻精品| 婷婷久久综合| 久久天天躁狠狠躁夜夜avapp| 久久国产精品无| 久久亚洲精品无码VA大香大香|