标签:mon preview else http should find java ota led
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 4572 Accepted Submission(s): 1459
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int N = 1000002;
int Next[N];
char S[N], T[N];
char str[510][2100];
int slen, tlen;//注意每次一定要计算长度
int len[510];
int vis[510];
vector<int>V;
void getNext(char *T,int tlen)
{
int j, k;
j = 0; k = -1; Next[0] = -1;
while(j < tlen)
if(k == -1 || T[j] == T[k])
Next[++j] = ++k;
else
k = Next[k];
}
/*
返回模式串T在主串S中首次出现的位置
返回的位置是从0开始的。
*/
int KMP_Index(char *S,int slen,char *T,int tlen)
{
int i = 0, j = 0;
getNext(T,tlen);
while(i < slen && j < tlen)
{
if(j == -1 || S[i] == T[j])
{
i++; j++;
}
else
j = Next[j];
}
if(j == tlen)
return i - tlen;
else
return -1;
}
int main()
{
int TT,Case=0;;
int i, cc,n,sum,maxx;
scanf("%d",&TT);
while(TT--)
{
memset(vis,0,sizeof(vis));
maxx=-1;
Case++;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%s",str[i]);
len[i]=strlen(str[i]);
}
for(int i=1;i<n;i++)
{
sum=0;
for(int j=0;j<i;j++)
{
if(!vis[j]){
if(KMP_Index(str[i],len[i],str[j],len[j])>=0)
vis[j]=1;
else
{
maxx=i;
break;
}
}
}
}
if(maxx==-1) printf("Case #%d: %d\n",Case,maxx);
else printf("Case #%d: %d\n",Case,maxx+1);
}
return 0;
}
标签:mon preview else http should find java ota led
原文地址:http://www.cnblogs.com/a249189046/p/7482205.html