(简单) 搜索 HOJ 1066 Substrings
来源:互联网 发布:网络购票岫岩到沈阳 编辑:程序博客网 时间:2024/06/05 02:44
Substrings
Source : ACM ICPC Tehran 2002 Preliminery ContestTime limit : 1 secMemory limit : 32 M
Submitted : 568, Accepted : 191
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 file 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
Sample Output
Input
The first line of the input file 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
23ABCDBCDFFBRCD2roseorchid
Sample Output
22
题意:给一系列字符串,找出一个字符串X使得任意给的字符串里面都能找到X或者是反过来的X,然后要输出最大的X的长度,这里有点坑 ,是字符的值得和最大的长度,而不是长度最长的。
思路: 暴搜吧 反正也是0ms过
代码:
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<string>
#include<deque>
#include<queue>
#include<math.h>
#include<vector>
using namespace std;
#define MAX 100000+10
#define MOD 99997
const int inf = 0xfffffff;
char input[110][110];
int len[110];
int n;
bool isOk(char s[] , int s_len)
{
int move = 1;
bool flag;
for (int i = 2 ; i <= n ; ++i)
{
flag = false;
for (int j = 1 ; j <= len[i]-s_len+1 ; ++j) if (input[i][j]==s[1])
{
int k = 1;
while (k<=s_len && s[k]==input[i][j+k-1]) ++k;
if (k==s_len+1)
{
flag = true;
break;
}
}
if (flag) continue;
for (int j = 1 ; j <= len[i]-s_len+1 ; ++j) if (input[i][j]==s[s_len])
{
int k = 1;
while (k<=s_len && input[i][j+k-1]==s[s_len-k+1]) ++k;
if (k>s_len)
{
flag = true;
break;
}
}
if (!flag) return false;
}
return true;
}
int main()
{
int T;
cin>>T;
while (T--)
{
scanf("%d",&n);
int k = 1;
for (int i = 1 ; i <= n ; ++i)
{
scanf("%s",input[i]+1);
len[i] = strlen(input[i]+1);
k = !k;
}
bool flag = false;
k = !k;
char X[110];
int X_len = 0;
int largest = -inf;
int ans = 0;
for (int i = 1 ; i <= len[1] ; ++i)
{
X_len = 0;
int j = i;
int sum = 0;
while (j <= len[1])
{
X[++X_len] = input[1][j];
sum += input[1][j];
if (sum>largest && isOk(X,X_len))
{
largest = sum;
ans = X_len;
}
++j;
}
}
printf("%d\n",ans);
}
}
0 0
- (简单) 搜索 HOJ 1066 Substrings
- hoj 1066 Substrings
- (简单) 搜索 HOJ 1097 Robot
- hdu 4158 hoj 2581 Go 简单搜索
- poj1111 hoj 1639 Image Perimeters 简单搜索
- Go hdu 4158 hoj 简单搜索
- (简单)搜索 HOJ 1022 Spacecraft Malfunction
- (简单)搜索 HOJ 1030 Labyrinth
- (简单) 搜索 HOJ 1044 Transportation
- (简单) 搜索 HOJ 1048 Cipher
- (简单)搜索 HOJ 1070 Word
- (简单)搜索 HOJ 1075 The Castle
- (简单) 搜索 HOJ 1085 Finding Rectangles
- (简单) 搜索 HOJ 1105 Egyptian Multiplication
- (简单) 搜索 最短路 HOJ 1121 Erdos Numbers
- (简单)搜索 HOJ 1692 Choose Your Own Adventure
- 搜索 HOJ 1629 Safecracker
- 搜索 HOJ 1394 Shortcut
- (简单)搜索 HOJ 1030 Labyrinth
- (简单) 搜索 HOJ 1044 Transportation
- (简单) 搜索 HOJ 1048 Cipher
- textview 使用自己的字体
- (中等) 搜索 HOJ 1049 sticks
- (简单) 搜索 HOJ 1066 Substrings
- (简单)搜索 HOJ 1070 Word
- (简单)搜索 HOJ 1075 The Castle
- (简单) 搜索 HOJ 1085 Finding Rectangles
- (简单) 搜索 HOJ 1097 Robot
- (中等) 线段树 HDU 3308 LCIS
- (简单) 搜索 HOJ 1105 Egyptian Multiplication
- (简单) 搜索 最短路 HOJ 1121 Erdos Numbers
- (基础) 树形dp HDU 1520 Anniversary party
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
共同债务
债务危机
债务关系
债务替代品
隐性债务
美国债务
什么是债务
债务英文
债务承担
清偿债务
有息债务
与债务
次级债务
长期债务
公司破产债务怎么办
夫妻共同债务司法解释
个人破产后债务怎么办
债务重组会计分录
离婚债务如何分担
债务纠纷起诉流程
婚前债务婚后是否共同承担
夫妻共同债务认定
共益债务和普通破产债权
夫妻债务4月1日新规定
无力偿还债务要坐牢吗
夫妻债务一方不知情
个人欠债务800万可以申请破产
破产重整债务谁来偿还
希腊债务危机
债务是什么意思
债权债务抵消
债权
债务人
全国首例个人债务清理案件m
全国首例个人债务清理案件4
迟延履行期间债务利息
法律规定2018年5种债务不用还
债务人无力偿还债务怎么办
有限责任公司破产债务怎么办
有限责任倒闭剩下债务谁承担
怎样能撇清婚内债务
程序博客网,程序员的互联网技术博客家园。csdn论坛精品 msdn技术资料都在这里