标签:des style blog http java color
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1492 Accepted Submission(s): 662
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <string.h> 5 #include <set> 6 using namespace std; 7 char s[1100000]; 8 int next[1100000]; 9 int get(char s[],int flag,int l) 10 { 11 int i,j,k,t; 12 i=k=0; 13 j=1; 14 while(i<l&&j<l&&k<l) 15 { 16 t=s[(i+k>=l?i+k-l:i+k)]-s[(j+k>=l?j+k-l:j+k)]; 17 if(!t)k++; 18 else 19 { 20 if(!flag) 21 { 22 if(t>0)i+=k+1; 23 else j+=k+1; 24 } 25 else 26 { 27 if(t<0)i+=k+1; 28 else j+=k+1; 29 } 30 if(i==j)j++; 31 k=0; 32 } 33 } 34 return i; 35 } 36 void getsnext(char s[],int l) 37 { 38 int i=1,j=0; 39 next[0]=0; 40 while(i<l) 41 { 42 if(j==0||s[i]==s[j]) 43 { 44 i++,j++; 45 next[i]=j; 46 } 47 else j=next[j]; 48 } 49 next[l-1]++; 50 } 51 int main() 52 { 53 while(~scanf("%s",s)) 54 { 55 int l=strlen(s); 56 int minaa=get(s,0,l); 57 int maxaa=get(s,1,l); 58 getsnext(s,l); 59 cout<<minaa+1<<" "<<((l%(l-next[l-1]))?1:l/(l-next[l-1])); 60 cout<<" "<<maxaa+1<<" "; 61 cout<<((l%(l-next[l-1]))?1:l/(l-next[l-1]))<<endl; 62 } 63 }
String Problem hdu 3374 最小表示法加KMP的next数组,布布扣,bubuko.com
String Problem hdu 3374 最小表示法加KMP的next数组
标签:des style blog http java color
原文地址:http://www.cnblogs.com/ERKE/p/3833062.html