POJ3080 Blue Jeans 最长公共子串
来源:互联网 发布:知乎live结束后购买 编辑:程序博客网 时间:2024/05/17 07:39
题目大意:给出n个长度为60的字符串,找出他们之间的最长公共子串的大小。
分析:刚开始以为是数状数组或KMP的题,后来发现暴力就可以过==
实现代码如下:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;#define maxn 105char str[maxn][maxn];int n;bool judge(int start,int end){ int i,j,k; for(i=1;i<n;i++) { for(j=0,k=start;j<60&&k<=end;) if(str[0][k]==str[i][j]) { k++;j++; } else { j=j-(k-start)+1;k=start; } if(k<=end) return 0; } return 1;}int main(){ int t; cin>>t; while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%s",str[i]); int ans=0,s=0; for(int i=0;i<60;i++) for(int j=0;j<=i;j++) if(judge(j,i)&&ans<=(i-j+1)) { ans=i-j+1; s=i; } if(ans<3) puts("no significant commonalities"); else { for(int i=s-ans+1;i<=s;i++) printf("%c",str[0][i]); printf("\n"); } } return 0;}
0 0
- POJ3080 Blue Jeans 最长公共子串
- POJ3080 Blue Jeans(KMP,求最长公共子串)
- Blue Jeans(poj3080,后缀数组,求最长公共子串)
- poj3080(Blue Jeans)kmp求多个串公共子串
- poj 3080 Blue Jeans (KMP+最长公共子串)
- poj 3080 Blue Jeans(最长公共子串)
- POJ 3080 Blue Jeans(KMP 最长公共子串)
- POJ 3080 Blue Jeans(KMP 最长公共子串)
- POJ 3080 Blue Jeans(KMP:最长连续公共子序列)
- POJ 3080/ ZOJ 2784 : Blue Jeans - 串匹配,最长公共子串
- poj 3080 Blue Jeans (多串最长公共子串 暴力)
- POJ 3080:Blue Jeans:枚举求解n个字符串的最长公共连续子串
- poj3080 Blue Jeans(串的暴力枚举)
- poj3080 blue Jeans
- poj3080 Blue Jeans-------KMP
- Blue Jeans poj3080
- POJ3080 Blue Jeans
- POJ3080:Blue Jeans
- 【2015/4/22】jsp学习笔记1---简述j2ee技术和初始jsp
- C语言快速排序算法及代码
- 数据库学习笔记系列(5)——分组查询
- android 手动设置时间 过期闹钟被触发
- 多核浏览器选择默认模式
- POJ3080 Blue Jeans 最长公共子串
- SQL统计查询 两次group
- Homework2-Introductoin to MATLAB
- XP桌面背景文件路径
- VS2010+QT5编程之解决中文乱码及一些编译未通过问题
- 非对称密钥-数字签名及数字证书
- UI之富文本编辑器-UEditor
- HDU Specialized Four-Digit Numbers
- jsp播放声音