Substrings

Time Limit: 1000ms
Memory Limit: 10000KB

This problem will be judged on PKU. Original ID: 1226
64-bit integer IO format: %lld      Java class name: Main

 
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.

 

Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string.

 

Output

There should be one line per test case containing the length of the largest string found.

 

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的更多相关文章

  1. POJ - 1226 Substrings (后缀数组)

    传送门:POJ - 1226 这个题跟POJ - 3294  和POJ - 3450 都是一样的思路,一种题型. POJ - 3294的题解可以见:https://www.cnblogs.com/li ...

  2. OpenJudge/Poj 1226 Substrings

    1.链接地址: http://bailian.openjudge.cn/practice/1226/ http://poj.org/problem?id=1226 2.题目: 总时间限制: 1000m ...

  3. POJ 1226 Substrings(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...

  4. POJ - 3294~Relevant Phrases of Annihilation SPOJ - PHRASES~Substrings POJ - 1226~POJ - 3450 ~ POJ - 3080 (后缀数组求解多个串的公共字串问题)

    多个字符串的相关问题 这类问题的一个常用做法是,先将所有的字符串连接起来, 然后求后缀数组 和 height 数组,再利用 height 数组进行求解. 这中间可能需要二分答案. POJ - 3294 ...

  5. 【POJ 1226】Substrings

    [链接]h在这里写链接 [题意] 给你n个字符串. 让你找一个字符串s. 设s'为这个字符串的逆序. 要求s或者s'在每个字符串里都能够找得到. 并且要求s的长度最长. 求出这个最长的串的长度. [题 ...

  6. POJ 1226 后缀数组

    题目链接:http://poj.org/problem?id=1226 题意:给定n个字符串[只含大小写字母],求一个字符串要求在n个串或者他们翻转后的串的出现过.输出满足要求的字符串的长度 思路:根 ...

  7. POJ 1225 Substrings

    http://poj.org/problem?id=1226 题意:给定n个串.求一个最长的串,使得这个串或者其反串在每个串中都出现过? 思路:先在大串里面加入正反串,然后二分,判定即可. #incl ...

  8. poj 1226

    跟3294比较类似,但是不需要输出具体的串,比较简单,只要把串反转连接上去解法就一样了. #include <iostream> #include <cstdio> #incl ...

  9. PKU 1226 Substrings(字符串匹配+暴搜KMP模板)

    原题大意:原题链接 给出n个字符串,找出一个最长的串s,使s或者s的反转字符串(只要其中一个符合就行)同时满足是这n个串的子串. 对于样例,第一组ABCD   BCDFF  BRCD最长的串就是CD; ...

随机推荐

  1. UVaLive 6680 Join the Conversation (DP)

    题意:给出n条发言,让你求最大的交流长度并输出标记顺序. 析:这个题要知道的是,前面的人是不能at后面的人,只能由后面的人at前面的,那就简单了,我们只要更新每一层的最大值就好,并不会影响到其他层. ...

  2. Commons-FileUpload 文件上传(模板)

    // 创建FileItem工厂函数 FileItemFactory FIF = new DiskFileItemFactory(); // 获取ServletFileUpload对象,使用工厂实例传入 ...

  3. E20171108-hm

    breadcrumb  n. 面包屑:面包心; 2.面包的松软(或柔软)部分;                    n.  网页导航区(a -> b -> c)

  4. bzoj 1603: [Usaco2008 Oct]打谷机【瞎搞】

    一棵树,碰到改变转向的边就异或一下,从1dfs一遍 #include<iostream> #include<cstdio> using namespace std; const ...

  5. 解决:阿里云ECS上启动tomcat后,第一次访问时间特别长

    Re在ECS上启动tomcat后,第一次访问时间特别长      2017-04-25 10:16:04 INFO com.world.socket.ServerSocketListener  25- ...

  6. 块级标签与预格式化文本标签----------大多数XHTML可以表示为两种类型的标签:块标签(block tag)和内联标签(inline tag)

    <html> <head> <meta charset="utf-8"> <title>块级标签</title> < ...

  7. Appium Python API 汇总(中文版)

    网络搜集而来,留着备用,方便自己也方便他人.感谢总结的人! 1.contexts contexts(self): Returns the contexts within the current ses ...

  8. Pycharm消除波浪线

    PyCharm使用了较为严格的PEP8检查规则,稍微有点错误就会出现波浪线提示.那么怎么消除这些波浪线呢?一个简单粗暴的方法就是:在编辑器的右下角有个小人形状的按钮,点开之后有个滚动条,将滚动条滑动到 ...

  9. Microsoft SQL Server学习(七)--函数视图

    系统函数 视图 索引 1.系统函数 (1) ()数学函数 Abs() 绝对值 Floor() 向下取整 Ceiling() 向上取整 Sin() 返回指定角度(以弧度为单位)的三角正弦值 Pi() 圆 ...

  10. 在Resource中使用x:Bind

    Build2015上,MS热情高涨的演示了x:Bind,一种新的Binding方式,新的方式有如下优点: 1更好的性能(内存占用,CPU占用) 2BuildTime的Binding 具体在Channe ...