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. robotframework - 基础关键词

    robotframework基础关键词如下: 1.可在python.notepad++ 编辑: *** Settings *** *** Test Cases ***variable ${a} Set ...

  2. Java多线程(四)isAlive

    isAlive 活动状态:线程处于正在运行或准备开始运行的状态 public class ISLiveDemo extends Thread { public void run() { System. ...

  3. UC浏览器中,设置了position: fixed 的元素会遮挡z-index值更高的同辈元素

    "UC浏览器中,设置了position: fixed 的元素会遮挡z-index值更高的同辈元素(非fixed)." 我们使用的artDialog弹窗中,在UC浏览器中,如果页面高 ...

  4. win7任务计划提示”该任务映像已损坏或已篡改“怎么处理

    https://jingyan.baidu.com/article/e75057f2038e2febc91a8915.html 在命令行窗口(cmd)执行命令:schtasks /query /v   ...

  5. 396 Rotate Function 旋转函数

    给定一个长度为 n 的整数数组 A .假设 Bk 是数组 A 顺时针旋转 k 个位置后的数组,我们定义 A 的“旋转函数” F 为:F(k) = 0 * Bk[0] + 1 * Bk[1] + ... ...

  6. PHP安装yaf在ubuntu下面的问题解决

    1.在执行make的时候出现如下错误: In file included from /root/yaf-2.1.2/yaf_router.c:28: /usr/include/php/ext/pcre ...

  7. Laravel5.1学习笔记22 Eloquent 调整修改

    Eloquent: Mutators Introduction Accessors & Mutators Date Mutators Attribute Casting Introductio ...

  8. codeforces_333B_水过

    B. Chips time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  9. day19-常用模块IV(re、typing)

    目录 re模块 typing模块 爬取音频 re模块 用来从字符串(文本)中查找特定的东西 1.元字符:有特殊意义的字符 ^ 从开头匹配 import re a = re.findall('^abc' ...

  10. CAD从二制流数据中加载图形(com接口Delphi语言)

    主要用到函数说明: _DMxDrawX::ReadBinStream 从二制流数据中加载图形,详细说明如下: 参数 说明 VARIANT varBinArray 二制流数据,是个byte数组 BSTR ...