Test instructions
n Personal siege One Ring, counter-clockwise numbering 1~n,a starting from 1 counterclockwise number k, b from n clockwise number m, selected 1 or 2 person at a time dole, output order
Ideas
Two-way Joseph Ring, the formula is not rolled out, with the simulation
Summarize
Starting with the array of analog linked list written, WA, intends to change again. I do not know why this problem card for a long time always wrong.
Simulation:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intMAXN = -;7 intN, K, m;8 intA[MAXN];9 intMain ()Ten { OneFreopen ("In.txt","R", stdin); A - while(Cin >> n >> k >> m &&N) { - for(inti =1; I <= N; i++) theA[i] =i; - intleft =N; - intP1 =1, p2 =N; - while(left) { + intCNT =0; - for(; CNT! = k;p1++){ + if(P1 = = n+1) P1 =1; A if(A[P1]) cnt++; at - } -p1--; - for(CNT =0; CNT! = m; p2--){ - if(P2 = =0) P2 =N; - if(A[P2]) cnt++; in - } top2++; +printf"%3d", p1); -left--; the if(P2! =p1) { *printf"%3d", p2); $left--;Panax Notoginseng } -A[P1] = a[p2] =0; the if(left) printf (","); + } Aprintf"\ n"); the } + return 0; -}
Uva133-the Dole Queue