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. ODP.NET Managed 相关文章收集

      一.Oracle 对.net支持的一些基础知识了解介绍. 1.早年的时候,微软自己做的有 System.Data.OracleClient. 现在已经成了过期类了.性能等都不是很好. 2.Orac ...

  2. 可视图linux--ubuntu的安装以及tool的安装

    1.下载ubuntu:http://cn.ubuntu.com/download/ 右键然后选择复制链接地址,然后将这个地址粘贴到迅雷,下载速度会比浏览器下载快. 2.创建虚拟机,安装ubuntu-- ...

  3. Java setAccessible方法作用

    在Java中可以通过反射进行获取实体类中的字段值,当未设置Field的setAccessible方法为true时,会在调用的时候进行访问安全检查,会抛出IllegalAccessException异常 ...

  4. bzoj [JSOI2010]Group 部落划分 Group【二分+并查集】

    我是zz吗这么简单都写错-- 一眼二分,然后判断的话是枚举点,然后计算这个点到已有联通块的最小距离,如果这个点到一些联通块的距离小于当前二分的val,则把这些联通块合并起来,这里用并查集维护,最后看这 ...

  5. 洛谷P4397 [JLOI2014]聪明的燕姿

    传送门 dfs的时候莫名其妙深度太大过不了……然后死活找不出哪里错…… 首先,约数和这东西是个积性函数,或者直接点的话就是如果$$n=p_1^{a_1}p_2^{a_2}p_3^{a_3}…p_m^{ ...

  6. ACM_01背包(恰好装满)

    背包2 Time Limit: 2000/1000ms (Java/Others) Problem Description: 有n个重量和价值分别为Wi,Vi的物品,现从这些物品中挑选出总量刚好为 W ...

  7. 数据传递-------@ModelAttribute

    package com.wh.handler; /** * @ModelAttribute绑定请求参数到命令对象 * @ModelAttribute一个具有如下三个作用: * * ①绑定请求参数到命令 ...

  8. 牛客网-3 网易编程题(1拓扑&2二叉树的公共最近祖先&3快排找第K大数)

    1. 小明陪小红去看钻石,他们从一堆钻石中随机抽取两颗并比较她们的重量.这些钻石的重量各不相同.在他们们比较了一段时间后,它们看中了两颗钻石g1和g2.现在请你根据之前比较的信息判断这两颗钻石的哪颗更 ...

  9. 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先

    给定一棵二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-s ...

  10. kafka启动时出现FATAL Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer) java.io.IOException: Permission denied错误解决办法(图文详解)

    首先,说明,我kafk的server.properties是 kafka的server.properties配置文件参考示范(图文详解)(多种方式) 问题详情 然后,我启动时,出现如下 [hadoop ...