#include <iostream>#include<algorithm>#include<string.h>#include<cstdio>#include<vector>using namespacestd;Const intmaxn=10005;structelem{Charstr[ the]; intLen; BOOL operator< (ConstElem &RHS)Const{ returnlen<rhs.len| | (LEN==RHS.LEN&&STRCMP (STR,RHS.STR) <=0); } BOOL operator== (ConstElem &RHS)Const{ returnLEN==RHS.LEN&&STRCMP (str,rhs.str) = =0; }}P[MAXN];Chars[ the];intMinrepresstation (CharSintLen) { inti =0, j =1, k =0; while(I < Len && J <Len) {k=0; while(K < Len && s[(i + k)%len] = = s[(j + k)%Len]) K++; if(k >=len) Break; if(s[(i + k)%len] > s[(j + k)%Len]) I= Max (i + k +1, J +1); ElseJ= Max (i +1, J + k +1); } returnmin (i, j);}intMain () {intN; while(SCANF ("%d", &n) = =1) { for(intI=0; i<n; i++) {scanf ("%s", s); P[i].len=strlen (s); intD=minrepresstation (S,p[i].len); for(intj=0;j<p[i].len; J + +) P[i].str[j]=s[(d+j)%P[i].len]; P[i].str[p[i].len]=0; } sort (P,p+N); intNum=unique (P,p+n)-Q; printf ("%d\n", num); } return 0;}
hdu2609 Minimal notation