POJ 3080 Blue Jeans(KMP)
来源:互联网 发布:java http获得响应 编辑:程序博客网 时间:2024/05/16 02:06
题意:有多个基因碱基序列(只由AGCT组成),在这些序列中找出一个最长的公共子串,如果长度相等,优先输出字典序较小的串。
思路:由于数据较小,所以直接枚举第一个串中的子串,然后依次对之后的串每次作一次KMP判断是否匹配即可。
注意:当串的长度相同时,要优先输出字典序较小的串。(尼玛最开始没看到好蛋疼)
# include<iostream># include<string># include<cstdio>using namespace std;char st1[1000],st2[10000],str[10000][10000];int next[10010];int num,l1,l2,i,j,k,start,end;void kmp1()//求next值{ int p,q; q=-1; next[0]=-1; for (p=1;p<=l2-1;p++) { while (q>-1&&st2[q+1]!=st2[p]) q=next[q]; if (st2[q+1]==st2[p]) q++; next[p]=q; }}void kmp2()//KMP函数{ int p,q; q=-1; for (p=0;p<=l1-1;p++) { while (q>-1&&str[k][p]!=st2[q+1]) q=next[q]; if (str[k][p]==st2[q+1]) q++; if (q==l2-1) { num++;//如果当前串与模式串匹配则num++ break; } }}int main(void){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n,t; cin>>t; while(t--) { int ok=0,max=-1; start=end=0; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%s",str[i]); //枚举第一个串中的每个子串作为模式串 for(i=0;i<=57;i++) for(j=i+2;j<=59;j++)//模式串从i开始到j { l2=j-i+1;//l2为模式串长度 l1=60;//l1为主串长度 int count=i; for(k=0;k<l2;k++)//将模式串存入str数组 st2[k]=str[1][count++]; kmp1();//求出模式串的next值 num=0; for(k=2;k<=n;k++)//对之后每一个串求一次KMP kmp2(); if(num==n-1) { ok=1; if(end-start<j-i) { start=i; end=j; } else if(end-start==j-i)//当两个模式串相等时要保证字典序 for(k=0;k<=end-start;k++) if(str[1][start+k]>str[1][i+k]) start=i,end=j; } } if(ok) { for(int temp=start;temp<=end;temp++) printf("%c",str[1][temp]); printf("\n"); } else printf("no significant commonalities\n"); } return 0;}
- POJ 3080 Blue Jeans KMP
- POJ 3080 Blue Jeans----kmp
- POJ 3080 Blue Jeans(KMP)
- POJ 3080 Blue Jeans KMP
- poj 3080 Blue Jeans(KMP)
- poj-3080 Blue Jeans(KMP)
- [poj 3080]Blue Jeans [kmp]
- POJ 3080 Blue Jeans KMP
- 【Kmp】Blue Jeans POJ
- poj 3080 Blue Jeans kmp+枚举
- [KMP或者暴力]POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans 暴力枚举+KMP
- POJ 3080 Blue Jeans (KMP)
- poj 3080 Blue Jeans ( 二分 + kmp)
- POJ 3080 Blue Jeans KMP+暴力
- poj 3080 Blue Jeans(KMP)
- POJ 3080 Blue Jeans KMP解法
- poj 3080 Blue Jeans(数据结构:KMP)
- MybatisGen1.0 Mybatis JavaBean Mapper生成工具
- ubuntu SSH 连接
- 百度谷歌互刷排名,互刷流量,刷下拉,刷相关搜搜【胖虎图图-互动点击专家】
- 百度竞价点击系统,互动点击软件【胖虎图图-互动点击专家】
- 连接mysql的时候出现:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- POJ 3080 Blue Jeans(KMP)
- Android TTS 中文 文字转语音 使用TextToSpeech Svox .
- 2013全新的开始
- JAVA正则表达式之标志表达式
- 搜索引擎常用的十大指令
- 九度Online Judge程序猿求职及面试
- coreseek 在windows下的编译(转)
- ZMQ_SNDHWM and ZMQ_RCVHWM should use type of int instead of uint64_t
- HDU 2068