HDOJ 5510-Bazinga【模拟】

来源:互联网 发布:网络买大麻暗语 编辑:程序博客网 时间:2024/06/04 21:16

Bazinga

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1468    Accepted Submission(s): 457


Problem Description
Ladies and gentlemen, please sit up straight.
Don't tilt your head. I'm serious.

For n given strings S1,S2,,Sn, labelled from 1 to n, you should find the largest i (1in) such that there exists an integer j (1j<i) and Sj is not a substring of Si.

A substring of a string Si is another string that occurs in Si. For example, ``ruiz" is a substring of ``ruizhang", and ``rzhang" is not a substring of ``ruizhang".
 

Input
The first line contains an integer t (1t50) which is the number of test cases.
For each test case, the first line is the positive integer n (1n500) and in the following n lines list are the strings S1,S2,,Sn.
All strings are given in lower-case letters and strings are no longer than 2000 letters.
 

Output
For each test case, output the largest label you get. If it does not exist, output1.
 

Sample Input
45ababczabcabcdzabcd4youlovinyouaboutlovinyouallaboutlovinyou5dedefabcdabcdeabcdef3abaccc
 

Sample Output
Case #1: 4Case #2: -1Case #3: 4Case #4: 3
 

Source
2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
解题思路:
就是找到一个最大的下标字符串,上面的字符串不是这一串的字串。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char map[2000][2000];int main(){int T;int yy=0;scanf("%d",&T);while(T--){int n,i,j,k;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%s",map[i]);}int ans=-1;for(i=n;i>1;i--){if(!strstr(map[i],map[i-1])){ans=max(ans,i);for(j=i-1,k=i+1;k<=n;k++){if(!strstr(map[k],map[j]))ans=max(ans,k);}}}printf("Case #%d: %d\n",++yy,ans);}return 0;} 


 
0 0
原创粉丝点击