Bazinga
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 331 Accepted Submission(s): 139
Problem Description
Ladies and gentlemen, please sit up straight.
Don't tilt your head. I'm serious.
For n
given strings
S
1
,S
2
,⋯,S
n![]()
, labelled from
1
to
n
, you should find the largest
i (1≤i≤n)
such that there exists an integer
j (1≤j<i)
and
S
j![]()
is not a substring of
S
i![]()
.
A substring of a string S
i![]()
is another string that occurs
in
S
i![]()
. For example, ``ruiz" is a substring of ``ruizhang", and ``rzhang" is not a substring of ``ruizhang".
Don't tilt your head. I'm serious.
![](https://i-blog.csdnimg.cn/blog_migrate/ef744836a56868c6bc6cc87863ee3092.jpeg)
For n
A substring of a string S
Input
The first line contains an integer
t (1≤t≤50)
which is the number of test cases.
For each test case, the first line is the positive integer n (1≤n≤500)
and in the following
n
lines list are the strings
S
1
,S
2
,⋯,S
n![]()
.
All strings are given in lower-case letters and strings are no longer than 2000
letters.
For each test case, the first line is the positive integer n (1≤n≤500)
All strings are given in lower-case letters and strings are no longer than 2000
Output
For each test case, output the largest label you get. If it does not exist, output
−1
.
Sample Input
4 5 ab abc zabc abcd zabcd 4 you lovinyou aboutlovinyou allaboutlovinyou 5 de def abcd abcde abcdef 3 a ba ccc
Sample Output
Case #1: 4 Case #2: -1 Case #3: 4 Case #4: 3
Source
Recommend
题目大意:就是让你找一个最大的i,是的最少存在一个0<j<i,字符串数sj不是si的子串
沈阳区域赛的题,太弱,并没有沈阳区域赛的资格,做重现的时候,感觉这个题不会很简单,就硬生生的写了200来行的在线ac自动机,,,死活超时。。原本想放弃了,看到讨论区里有说有简单地方法,可以用strstr过,于是就想了想,暴力肯定超时,它是从上往下有积累的很多串已经是一个串的子串了,和这个串比了,就没必要再和他的子串比了,,于是一顿瞎搞就过了。。第六,,
ac代码
1 | Hacker_vision | 156MS | 2648K | 1477B | G++ | 2015-10-31 18:00:50 |
2 | _JM | 171MS | 2672K | 1135B | G++ | 2015-10-31 17:53:30 |
3 | 戦い | 218MS | 2624K | 1539B | G++ | 2015-10-31 21:54:18 |
4 | 马孟起 | 249MS | 2644K | 1040B | G++ | 2015-11-01 13:59:16 |
5 | preserve | 265MS | 2672K | 1026B | C++ | 2015-11-01 11:19:40 |
6 | XY_ | 280MS | 2716K | 729B | C++ | 2015-11-01 20:41:08 |
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
char str[505][2002];
int next[2002];
int cc[505];
int n,m;
int main()
{
int t,c=0;
scanf("%d",&t);
while(t--)
{
int num;
scanf("%d",&num);
int i,j,k;
for(i=1;i<=num;i++)
scanf("%s",str[i]);
int ans=-1;
int flag=0;
for(i=num;i>1;i--)
if(!strstr(str[i],str[i-1]))
{
ans=max(ans,i);
for(j=i-1,k=i+1;k<=num;k++)
if(!strstr(str[k],str[j]))
ans=max(ans,k);
}
printf("Case #%d: %d\n",++c,ans);
}
}