Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4350
More than 12 years old, with 1001 questions.
Shuffling, N gives a lot.
So as long as we find the loop section, modulo n out, and then perform the brute force operation, the remaining time complexity will be very low ~~~
It seems that the cycle section they are looking for is the smallest public multiple of (R-l + 1) and r... But what I am looking for is the maximum common number GCD between them, and then the cyclic section is R/GCD...
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <queue> # include <algorithm> using namespace STD; int gcd (int, int B) {return B = 0? A: gcd (B, A % B) ;}int main () {int T, TT; int s [53], TMP [53]; int n, l, R; scanf ("% d", & T); For (TT = 1; TT <= T; TT ++) {for (INT I = 1; I <= 52; I ++) scanf ("% d", & S [I]); scanf ("% d", & N, & L, & R ); int G = gcd (R, R-l + 1); N % = (R/g); While (n --) {for (INT I = 0; I <= R-l; I ++) TMP [I] = s [L + I]; for (INT I = 1; I <L; I ++) TMP [R-l + I] = s [I]; for (INT I = R + 1; I <= 52; I ++) TMP [I-1] = s [I]; for (INT I = 0; I <52; I ++) s [I + 1] = TMP [I];} printf ("case # % d:", TT); For (INT I = 1; I <= 52; I ++) printf ("% d ", s [I]); puts ("");} return 0 ;}