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

            poj3080

            Blue Jeans
            Time Limit: 1000MS
            Memory Limit: 65536K
            Total Submissions: 8079
            Accepted: 3376

            Description

            The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.

            As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be correlated with individual survey information to identify new genetic markers.

            A DNA base sequence is noted by listing the nitrogen bases in the order in which they are found in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and cytosine (C). A 6-base DNA sequence could be represented as TAGACC.

            Given a set of DNA base sequences, determine the longest series of bases that occurs in all of the sequences.

            Input

            Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:
            • A single positive integer m (2 <= m <= 10) indicating the number of base sequences in this dataset.
            • m lines each containing a single base sequence consisting of 60 bases.

            Output

            For each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string "no significant commonalities" instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.

            Sample Input

            3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

            Sample Output

            no significant commonalities AGATAC CATCATCAT 

            Source

            South Central USA 2006


            暴力 枚舉+kmp驗證

            我現(xiàn)在終于知道一個好模板有多重要了

            我的渣渣kmp,讓我wa過無數(shù)次題目了
            void getnext()
            {
                
            long i,j;
                j
            =-1;
                p[
            0]=-1;//zheli -1
                for (i=1;i<=m-1;i++)
                {
                    
            while ((j!=-1)&&(t[j+1]!=t[i])) j=p[j];//zheli -1
                    if (t[j+1]==t[i]) j=j+1;
                    p[i]
            =j;
                }
            }
            void kmp()
            {
                
            int i,j;
                j
            =-1;
                
            for (i=0;i<=n-1;i++)
                {
                    
            while ((j!=-1)&&(t[j+1]!=s[i])) j=p[j];//zheliyeshi
                    if (t[j+1]==s[i]) j++;
                    
            if (j==m-1)
                    {
                        printf(
            "Find at %d !",i-j+2);
                        j
            =p[j];
                    }
                }
            }
            //就因為這個,改到崩潰


            code
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;
            char str[15][105];
            char strt[100],old[100],ans[100];
            int p[100];
            int len,n,l1;
            void getnext()
            {
                
            int i,j;
                memset(p,
            0,sizeof(p));
                j
            =-1;
                p[
            0]=-1;
                
            for (i=1;i<strlen(strt);i++)
                {
                    
            while ((j!=-1)&&(strt[j+1]!=strt[i])) j=p[j];
                    
            if (strt[j+1]==strt[i]) j=j+1;
                    p[i]
            =j;
                }
            }
            bool kmp(char str1[])
            {
                
            int i,j,len2;
                len2
            =strlen(strt);
                j
            =-1;
                
            for (i=0;i<60;i++)
                {
                    
            while ((j!=-1)&&(strt[j+1]!=str1[i])) j=p[j];
                    
            if (strt[j+1]==str1[i]) j++;
                    
            if (j==len2-1)
                    {
                        
            return 1;
                    }
                }
                
            if (j!=len2-1)return 0;
                
            else return 1;
            }
            bool cmp1(char strx[],char stry[])
            {
                
            int len1;
                len1
            =strlen(strx);
                
            int len2;
                len2
            =strlen(stry);
                
            int lenx=len1<len2?len1:len2;
                
            for(int i=0; i<lenx; i++)
                {
                    
            if (strx[i]>stry[i])
                    {
                        
            return 1;
                    }
                    
            else if(strx[i]<stry[i])
                    {
                        
            return 0;
                    }
                }
                
            if(len1>len2) return 1;
                
            else return 0;
            }
            int main()
            {
                
            int t,i,j,k;
                scanf(
            "%d",&t);
                
            while(t--)
                {
                    scanf(
            "%d",&n);
                    
            for(i=1; i<=n; i++)
                        scanf(
            "%s",str[i]);
                    len
            =60;
                    l1
            =0;
                    memset(ans,
            0,sizeof(ans));
                    memset(strt,
            0,sizeof(strt));
                    
            for(j=3; j<=len; j++)
                        
            for(i=0; i<=len-j; i++)
                        {
                            strcpy(old,strt);
                            
            for(k=i; k<i+j; k++)
                                strt[k
            -i]=str[1][k];
                            strt[k
            -i]='\0';
                           
            // puts(strt);
                           if(strcmp(old,strt)==0)continue;
                            getnext();
                            
            bool flag;
                            flag
            =true;
                            
            for(k=2; k<=n; k++)
                            {
                                
            if(kmp(str[k])==0)
                                {
                                    flag
            =false;
                                    
            break;
                                }
                            }
                            
            if(flag)
                            {
                                
            if(ans[0]==0)
                                    strcpy(ans,strt);
                                
            else
                                {
                                    
            if(strlen(strt)>strlen(ans))
                                    {
                                        
            //puts(ans);
                                        strcpy(ans,strt);
                                    }
                                    
            else if(strlen(strt)==strlen(ans))
                                    {
                                        
            if(cmp1(ans,strt))
                                        {
                                        
            //    puts(ans);
                                            strcpy(ans,strt);
                                        }
                                    }
                                }

                            }
                        }
                    
            if(ans[0]!=0) printf("%s\n",ans);
                    
            else printf("no significant commonalities\n");
                }
                
            return 0;
            }

            posted on 2012-07-23 21:50 jh818012 閱讀(185) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2012年2月>
            2930311234
            567891011
            12131415161718
            19202122232425
            26272829123
            45678910

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因為 3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點擊標(biāo)題查看
            • --王私江
            久久久精品日本一区二区三区| 久久国产精品国产自线拍免费| 久久精品国产亚洲5555| 欧美久久久久久午夜精品| 国产精品久久久久蜜芽| 久久大香香蕉国产| 九九热久久免费视频| 丁香色欲久久久久久综合网| 久久99精品国产99久久6男男| 亚洲国产成人乱码精品女人久久久不卡 | 国产成人久久精品二区三区| 人人狠狠综合久久亚洲高清| 精品久久久久久无码专区| 久久久久亚洲AV成人网人人软件 | 国产一久久香蕉国产线看观看| 久久涩综合| 97久久精品午夜一区二区| 久久综合亚洲色HEZYO社区| 久久亚洲精品中文字幕三区| 午夜不卡久久精品无码免费| 国产精久久一区二区三区| 久久久噜噜噜久久熟女AA片| 狠狠色丁香婷婷久久综合五月| 香蕉久久夜色精品国产小说| 久久精品国产亚洲AV电影| 久久青青草视频| 怡红院日本一道日本久久| 久久国产精品成人影院| 亚洲中文字幕无码久久综合网| 欧美粉嫩小泬久久久久久久| 99久久国产亚洲高清观看2024| 97久久国产亚洲精品超碰热| 无码国产69精品久久久久网站| 欧美精品乱码99久久蜜桃| 欧美性大战久久久久久| 亚洲&#228;v永久无码精品天堂久久 | 亚洲精品无码久久毛片| 久久综合九色欧美综合狠狠| 污污内射久久一区二区欧美日韩 | 久久久国产视频| 久久婷婷五月综合色99啪ak|