Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=4162
Test instructions
The minimum representation of the first order difference chain of a given character.
Exercises
First order difference chain is obtained, and then the minimum representation of first order difference chain is obtained.
Code:
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Const intMAXN = 3e5 +Ten;CharS1[MAXN],S2[MAXN];intSolveChar*s) {inti =0, j =1, k =0, len=strlen (s); while(I < Len&&j < len&&k<Len) { intt = s[(i + k)% len]-s[(j + k)%Len]; if(!t) k++; Else { if(T >0) i = i + K +1; ElseJ = j + K +1; if(i = = j) J + +; K=0; } } returnI < J?i:j;}intMain () { while(SCANF ("%s", s1) = =1) { intLen =strlen (S1); for(inti =0; i < Len; i++) {S2[i]= (s1[(i +1)% Len]-s1[i] +8) %8+'0'; } S2[len]=' /'; //cout << S2 << Endl; intpos =solve (S2); for(inti =0; i < Len; i++) {printf ("%c", s2[(pos + i)%Len]); } printf ("\ n"); } return 0;}
HDU 4162 Shape Number