Title: http://acm.hdu.edu.cn/showproblem.php?pid=4162
Test instructions: Given a string consisting of only 0-7 digits. Now, a new string is constructed from the original string, and the new string is constructed: the difference between the numbers in the adjacent 2 positions. If negative, add 8 and ask what is a dictionary-ordered minimum isomorphism string for a newly constructed string?
Idea: After the new string is constructed according to test instructions, then the minimum representation is given.
#define_crt_secure_no_deprecate#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<vector>using namespacestd;Const intMAXN =300000+5; typedefLong Long intLL;#defineINF 0x3f3f3f3fintMinrepresentation (int*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;}intSTR[MAXN];CharS[MAXN];intMain () { while(~SCANF ("%s", s)) { intLen =strlen (s); for(inti =0; i < Len; i++) {//construct a new string if(i = = Len-1) {Str[i]= (((s[0] -'0') +8-(S[i]-'0')) %8); } Else{Str[i]= (((s[i+1] -'0') +8-(S[i]-'0')) %8); } } intStart =minrepresentation (Str,len); for(inti =0; i < Len; i++) {printf ("%d", str[(start + i)%Len]); } printf ("\ n"); } return 0;}
HDU 4162 Minimum notation