/* This is another solution to mt2-4.txt. */ /* alive[0] means that man 1 is alive, alive[1] means that man 2 is alive, etc. e is the position of the man just executed. Memory pictures: m e a[0] a[1] a[2] a[3] a[4] a[5] a[6] 7 -1 1 1 1 1 1 1 1 7 0 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 7 2 1 1 1 1 1 1 1 print 3 6 2 1 1 0 1 1 1 1 6 3 1 1 0 1 1 1 1 6 4 1 1 0 1 1 1 1 6 5 1 1 0 1 1 1 1 print 6 5 5 1 1 0 1 1 0 1 5 6 1 1 0 1 1 0 1 5 0 1 1 0 1 1 0 1 5 1 1 1 0 1 1 0 1 print 2 4 1 1 0 0 1 1 0 1 4 3 1 0 0 1 1 0 1 4 4 1 0 0 1 1 0 1 4 6 1 0 0 1 1 0 1 print 7 3 6 1 0 0 1 1 0 0 3 0 1 0 0 1 1 0 0 3 3 1 0 0 1 1 0 0 3 4 1 0 0 1 1 0 0 print 5 2 4 1 0 0 1 0 0 0 2 0 1 0 0 1 0 0 0 2 3 1 0 0 1 0 0 0 2 0 1 0 0 1 0 0 0 print 1 1 0 0 0 0 1 0 0 0 1 3 0 0 0 1 0 0 0 1 3 0 0 0 1 0 0 0 1 3 0 0 0 1 0 0 0 print 4 0 3 0 0 0 1 0 0 0 */ #include int main(void) { int alive[100]; int m; int c; int e; int i; scanf("%d",&m); scanf("%d",&c); if (m > 100) m = 100; /* avoid buffer overflow */ for (i = 0;i < m;++i) alive[i] = 1; for (i = m;i < 100;++i) alive[i] = 0; e = -1; while (m > 0) { /* men are still alive */ for (i = 0;i < c;++i) { do { ++e; if (e >= 100) e = 0; } while (!alive[e]); } printf("%d\n",e + 1); alive[e] = 0; --m; } return 0; }