# Include <iostream> # include <cstdio> # include <vector> # include <algorithm> # include <functional> # include <map> using namespace STD; int Joseph _ m (int K) {vector <int> Vint, vint_ B; int I, j, M; int boys; for (I = 0; I <2 * k; I ++) VINT. push_back (I + 1); vint_ B = Vint; For (M = k + 1; ++ m) {boys = 2 * k; // There are 2 k boys in total, the first K are good boysj = 0; Vint = vint_ B; for (I = 0; I <K; I ++) // internal loop K Delete K boys {J = m % boys; If (j = 0) J = boys; If (VINT [J-1 ]> = 1 & Vint [J-1] <= k) break; VINT. Erase (VINT. Begin () + J-1); If (J! = Boys) rotate (VINT. begin (), VINT. begin () + J-1, VINT. end (); -- boys;} if (I = k) break;} return m;} void Init (vector <int> & VINT) {VINT. push_back (0); VINT. push_back (2); VINT. push_back (7); VINT. push_back (5); VINT. push_back (30); VINT. push_back( 169); VINT. push_back( 441); VINT. push_back( 1872); VINT. push_back( 7632); VINT. push_back( 1740); VINT. push_back( 93313); VINT. push_back( 459901); VINT. push_back( 1358657); VINT. push_back (250 4881); VINT. push_back (5); VINT. push_back (30);} int main () {// freopen ("in.txt", "r", stdin); vector <int> Vint; Init (VINT); int K; // 0 <k <14 While (CIN> K & K! = 0) {// cout <Joseph ph_m (k) <Endl; cout <Vint [k] <Endl ;}return 1 ;}
I did not find any good method for this question. I copied a shortcut, that is, I used a stupid method to calculate the M corresponding to the input 1-14, then wrote it to the table, and directly looked up and output the table.