Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一直Time Limit Exceeded是怎么回事?#include <iostream> #include <stdio.h> #include <string.h> #include <fstream> #define MAXN 400000 using namespace std; char name[MAXN+10]; char temp[MAXN+10]; int len[MAXN+10]; int next[MAXN+10]; int get_next(const char *str) { int j = 0, k = -1; memset(next, 0 ,sizeof(next)); next[0] = -1; while(j < strlen(str)) { if(k==-1 || str[j]==str[k]) { ++j; ++k; //if(str[j] != str[k]) next[j] = k; //else //next[j] = next[k]; } else k = next[k]; } return next[j]; } int main() { //freopen("E:\\in.txt","r",stdin); while(scanf("%s",name) != EOF ) { len[0] = strlen(name); int pos = 1; //记录有多少个cur int cur; cur = get_next(name); //len[pos++] = cur; while(cur > 0) { len[pos++] = cur; //int i; /*for( i=0; i<cur; i++) //新的 temp[i] = name[i]; temp[i] = '\0'; */ /*cur = get_next(temp);*/ //没必要再计算了 cur = next[cur]; //printf("%d\n",cur); //len[pos++] = cur; } for(int j=pos-1; j>=0; j--) printf("%d ",len[j]); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator