http://acm.hdu.edu.cn/search.php?field=problem&key=2015ACM%2FICPC%D1%C7%D6%DE%C7%F8%C9%F2%D1%F4%D5%BE-%D6%D8%CF%D6%C8%FC%A3%A8%B8%D0%D0%BB%B6%AB%B1%B1%B4%F3%D1%A7%A3%A9&source=1&searchmode=source

 

http://acm.hdu.edu.cn/showproblem.php?pid=5510

题意:

解法:

 

 1 //#define debug
 2 //#define txtout
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<cmath>
 7 #include<cctype>
 8 #include<ctime>
 9 #include<iostream>
10 #include<algorithm>
11 #include<vector>
12 #include<queue>
13 #include<stack>
14 #include<map>
15 #include<set>
16 #define mt(a,b) memset(a,b,sizeof(a))
17 using namespace std;
18 typedef long long LL;
19 const double eps=1e-8;
20 const double pi=acos(-1.0);
21 const int inf=0x3f3f3f3f;
22 const int M=1e5+10;
23 int n;
24 char a[512][2048];
25 int solve() {
26     if(n==1) return -1;
27     int s=0,t=1,result=-1;
28     while(t<n){
29         if(strstr(a[t],a[s])){
30             s++;
31             if(s==t){
32                 t++;
33             }
34             continue;
35         }
36         result=max(result,t+1);
37         t++;
38     }
39     return result;
40 }
41 int main() {
42 #ifdef txtout
43     freopen("in.txt","r",stdin);
44     freopen("out.txt","w",stdout);
45 #endif
46     int t;
47     while(~scanf("%d",&t)) {
48         int cas=1;
49         while(t--) {
50             scanf("%d",&n);
51             for(int i=0; i<n; i++) {
52                 scanf("%s",a[i]);
53             }
54             printf("Case #%d: %d\n",cas++,solve());
55         }
56     }
57     return 0;
58 }
View Code

相关文章: