Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2609
Test instructions: given n loop chain [string], ask how many essentially different chains [strings] (if a loop chain can be found by finding a starting point to make the same as the other strings, then the 2 chains are considered the same.) is to ask for a different structure of the string)
Idea: To find the homogeneous string can be used in the smallest notation, and then determine whether the equality can be known whether the 2 are isomorphic. The reuse is set
#define_crt_secure_no_deprecate#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<vector>#include<Set>using namespacestd;Const intMAXN =10000+5; typedefLong Long intLL;#defineINF 0x3f3f3f3fintMinrepresentation (Char*s,intl) { inti =0, j =1, k =0; while(I < L&&j < l&&k <l) { intLi, LJ; Li= (i + k) >= l? i + K-L: i +K; LJ= (j + k) >= l? J + K-L: J +K; if(S[li] = =S[LJ]) {k++; } Else{ if(s[li]>S[LJ]) {i= i + K +1; } Else{J= j + k +1; } if(i = =j) {J++; } k=0; } } returnI < J?i:j;}Charstr[maxn][ the];Set<string>se;intMain () {intN; while(~SCANF ("%d", &N)) {se.clear (); for(inti =0; I < n; i++) {scanf ("%s", Str[i]); intLen =strlen (Str[i]); intStart =minrepresentation (Str[i], Len); stringMinstr; for(intj =0; J < Len; J + +) {//get the homogeneous string with the smallest dictionary orderMinstr + = str[i][(j + start)%Len]; } if(!Se.count (MINSTR)) {Se.insert (MINSTR); }} printf ("%d\n", Se.size ()); } return 0;}
HDU 2609 Minimum notation