Meaning: 1 to n are arranged clockwise. Take m for the first time, and then take k in the clockwise direction ...... Until there is only one number left, what is the last number left? (2n10000, 1k10000, 1mn)
--> After reading rujia's book for more than a day, I cannot figure out the last step. In the end, I am still using my own ideas ......
Set d [I] to number n numbers starting from 0 clockwise. Delete 0 for the first time, delete one number for each k, and then delete the remaining number for each k.
In fact, d [I] is the number of digits offset clockwise.
State transition equation:
D [I] = (k-1 + d [I-1]) % (n-1) + 1;
(After 0 is deleted, 1, 2 ,..., n, minus 1 to get 0, 1, 2 ,..., n-1, so the original Delete k --> K-1, clockwise Offset d [I-1] bit, modulo, add 1 back to the original number)
[Cpp]
# Include <cstdio>
Using namespace std;
Const int maxn = 10000 + 10;
Int d [maxn]; // d [I] indicates that the number of I is deleted from 0, and the remaining number is deleted.
Int main ()
{
Int n, k, m, I;
D [1] = 0;
While (~ Scanf ("% d", & n, & k, & m ))
{
If (! N &&! K &&! M) return 0;
For (I = 2; I <= n; I ++) d [I] = (k-1 + d [I-1]) % (I-1) + 1;
Int ret = (m-1 + d [n]) % n + 1;
Printf ("% d \ n", ret );
}
Return 0;
}
# Include <cstdio>
Using namespace std;
Const int maxn = 10000 + 10;
Int d [maxn]; // d [I] indicates that the number of I is deleted from 0, and the remaining number is deleted.
Int main ()
{
Int n, k, m, I;
D [1] = 0;
While (~ Scanf ("% d", & n, & k, & m ))
{
If (! N &&! K &&! M) return 0;
For (I = 2; I <= n; I ++) d [I] = (k-1 + d [I-1]) % (I-1) + 1;
Int ret = (m-1 + d [n]) % n + 1;
Printf ("% d \ n", ret );
}
Return 0;
}