POJ 1226 Substrings
Substrings
This problem will be judged on PKU. Original ID: 1226
64-bit integer IO format: %lld Java class name: Main
Input
Output
Sample Input
2
3
ABCD
BCDFF
BRCD
2
rose
orchid
Sample Output
2
2
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
string str[];
int main() {
int t,i,j,k,n;
bool flag;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i = ; i < n; i++)
cin>>str[i];
sort(str,str+n);
flag = false;
for(k = str[].length(); k; k--){
for(i = ; i + k <= str[].length(); i++){
string a = str[].substr(i,k);
string b(a.rbegin(),a.rend());
for(j = ; j < n; j++)
if(str[j].find(a) == - && str[j].find(b) == -) break;
if(j == n) {flag = true;break;}
}
if(flag) break;
}
flag?printf("%d\n",k):puts("");
}
return ;
}
POJ 1226 Substrings的更多相关文章
- POJ - 1226 Substrings (后缀数组)
传送门:POJ - 1226 这个题跟POJ - 3294 和POJ - 3450 都是一样的思路,一种题型. POJ - 3294的题解可以见:https://www.cnblogs.com/li ...
- OpenJudge/Poj 1226 Substrings
1.链接地址: http://bailian.openjudge.cn/practice/1226/ http://poj.org/problem?id=1226 2.题目: 总时间限制: 1000m ...
- POJ 1226 Substrings(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...
- POJ - 3294~Relevant Phrases of Annihilation SPOJ - PHRASES~Substrings POJ - 1226~POJ - 3450 ~ POJ - 3080 (后缀数组求解多个串的公共字串问题)
多个字符串的相关问题 这类问题的一个常用做法是,先将所有的字符串连接起来, 然后求后缀数组 和 height 数组,再利用 height 数组进行求解. 这中间可能需要二分答案. POJ - 3294 ...
- 【POJ 1226】Substrings
[链接]h在这里写链接 [题意] 给你n个字符串. 让你找一个字符串s. 设s'为这个字符串的逆序. 要求s或者s'在每个字符串里都能够找得到. 并且要求s的长度最长. 求出这个最长的串的长度. [题 ...
- POJ 1226 后缀数组
题目链接:http://poj.org/problem?id=1226 题意:给定n个字符串[只含大小写字母],求一个字符串要求在n个串或者他们翻转后的串的出现过.输出满足要求的字符串的长度 思路:根 ...
- POJ 1225 Substrings
http://poj.org/problem?id=1226 题意:给定n个串.求一个最长的串,使得这个串或者其反串在每个串中都出现过? 思路:先在大串里面加入正反串,然后二分,判定即可. #incl ...
- poj 1226
跟3294比较类似,但是不需要输出具体的串,比较简单,只要把串反转连接上去解法就一样了. #include <iostream> #include <cstdio> #incl ...
- PKU 1226 Substrings(字符串匹配+暴搜KMP模板)
原题大意:原题链接 给出n个字符串,找出一个最长的串s,使s或者s的反转字符串(只要其中一个符合就行)同时满足是这n个串的子串. 对于样例,第一组ABCD BCDFF BRCD最长的串就是CD; ...
随机推荐
- IDEA Artifacts问题
如果你使用的IDEA并且无论如何都ClassNotFound异常的话,可以看看其中一种可能的解决方案 第一步:打开Project Struture-->Modules-->点击项目--&g ...
- bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富【记忆化搜索+剪枝】
c[x][y]为从(x,y)到(n,m)的最大值,记忆化一下 有个剪枝是因为y只能+1所以当n-x>m-y时就算x也一直+1也是走不到(n,m)的,直接返回0即可 #include<ios ...
- bzoj 1596: [Usaco2008 Jan]电话网络【贪心】
dfs,如果一个点的儿子.本身.父亲都没有塔,就在父亲上建一个 原理不明-- #include<iostream> #include<cstdio> using namespa ...
- bzoj1076: [SCOI2008]奖励关(期望dp+状压dp)
1076: [SCOI2008]奖励关 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2989 Solved: 1557[Submit][Statu ...
- npm更换为淘宝镜像源
1.通过config命令 1 2 npm config set registry http://registry.cnpmjs.org npm info underscore (如果上面配置正确这 ...
- 在sql语句中使用关键字
背景 开发过程中遇到了遇到了一句sql语句一直报错,看了一下字段名和表名都对应上了,但是还是一直报错 sql语句如下: update table set using = ""hh ...
- 在控制台中输出 ASP.NET 网站的跟踪信息
实现方法: 1. 可以在 C# 代码中调用 System.Diagnostics.Debug.WriteLine() 来实现. 其效果类似于在控制台应用程序中调用 Console.WriteLine( ...
- 在Azure Ubunt Server 14.04虚机中使用Deep-Visualization-Toolbox
参考网站 a) https://zhuanlan.zhihu.com/p/24833574?utm_source=tuicool&utm_medium=referral b) ht ...
- js类型识别
typeof总结: 可以识别标准类型(Null除外) 不能识别具体的对象类型(Function除外) Object.prototype.toString总结: 可以识别标准类型和内置对象类型 不能识别 ...
- Android(java)学习笔记205:JNI之编写jni程序适配所有处理器型号
1. 还是以"02_两个数相加"为例,你会发现这个jni程序只能在ARM处理器下运行,如下: 如果我们让上面的程序运行在x86模拟器上,处理平台不对应,报如下错误: 03-29 ...