Blue Jeans - POJ 3080(多串的共同子串)
#include<stdio.h>
#include<string.h> const int MAXN = ;
const int oo = 1e9+; char s[MAXN][MAXN];
int next[MAXN]; void GetNext(char s[])
{
int i=, j=-, N=strlen(s);
next[] = -; while(i < N)
{
if(j==- || s[i]==s[j])
next[++i] = ++j;
else
j = next[j];
}
}
bool KMP(char a[], char s[])
{
int i=, j=;
int Na=strlen(a), Ns = strlen(s); while(i < Na)
{
while(j==- || (a[i]==s[j] && i<Na) )
i++, j++; if(j == Ns)return true; j = next[j];
} return false;
} int main()
{
int T; scanf("%d", &T); while(T--)
{
int i, j, len, M, MaxLen=;
char ans[MAXN] = "Z"; scanf("%d", &M); for(i=; i<M; i++)
scanf("%s", s[i]); for(len=; len>=; len--)
for(i=; i<=MaxLen-len; i++)
{///枚举第一个串的所有子串
char b[MAXN]={}; strncpy(b, s[]+i, len);
GetNext(b); for(j=; j<M; j++)
{
if(KMP(s[j], b) == false)
break;
} if(j==M && strcmp(ans, b) > )
strcpy(ans, b); if(ans[] != 'Z' && i==MaxLen-len)
i=, len = ;///跳出循环
} if(ans[] == 'Z')
printf("no significant commonalities\n");
else
printf("%s\n", ans);
} return ;
}
Blue Jeans - POJ 3080(多串的共同子串)的更多相关文章
- (字符串 KMP)Blue Jeans -- POJ -- 3080:
链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...
- Blue Jeans POJ 3080 寻找多个串的最长相同子串
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- Match:Blue Jeans(POJ 3080)
DNA序列 题目大意:给你m串字符串,要你找最长的相同的连续字串 这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities #in ...
- Blue Jeans - poj 3080(后缀数组)
大致题意: 给出n个长度为60的DNA基因(A腺嘌呤 G鸟嘌呤 T胸腺嘧啶 C胞嘧啶)序列,求出他们的最长公共子序列 使用后缀数组解决 #include<stdio.h> #include ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
随机推荐
- hdoj 2049 错排
代码: #include <stdio.h> int main(){ int n,a,b,i,j; __int64 s[22],h[22]; s[1]=0; s[2]=1; s[3]=2; ...
- HDU 3359 Kind of a Blur(高斯消元)
题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B,求矩阵A ...
- 使用require.js时,解决AMD封装jquery1.4.1的问题。
require.config({ baseUrl: "js/", paths: { "jquery": "jquery-1.4.1.min" ...
- java编码转化方案-备用
import java.io.UnsupportedEncodingException; /** * 转换字符串的编码 */ public class changeCharSet { /** 7位AS ...
- linux防火墙解封某端口
首先,使用netstat –tunlp查看是否23端口被防火墙封掉了: 再使用iptables修改设置, # iptables -I INPUT -p tcp --dport 23 –jACCEPT ...
- CentOS7开机启动管理systemd简介及使用
systemd提供更优秀的框架以表示系统服务间的依赖关系实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果systemd的目标是:尽可能启动更少进程:尽可能将更多进程并行启动.sy ...
- Asp.net GridView 72般绝技
快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠 ...
- MySQL Procedure(MySQL存储过程)[转]
------Creating Stored Procedures in MySQL------ --Make sure you have version 5 of MySQL: SELECT VE ...
- 那些年被我坑过的Python——第十章Broker(rabbitMQ/redis)
基于RabbitMQ的direct任务驱动异步RPC程序实现: RPC_dispatcher指令分发器: #!/usr/bin/env python # -*- coding:utf-8 -*- __ ...
- openerp 报表字段 report_rml_content_data
按需求修改一个报表,本想按照打印出来的报表内容搜索rml文件,找到需要修改的rml问加. 但是发现搜索不到,后来查询报表动作,确认对应的rml文件中,没有发现 “报表中” 的字串. 猜测可能是rml直 ...