1 #include <bits/stdc++.h> 2 using namespace std; 3 bool vis[10010]; //vis[i]=true表示i已经出局 4 int main() { 5 int m, n; 6 cin >> m >> n; 7 int t = 0; //当前数到的数字 8 int cnt = 0; //当前已经出局的人数 9 for (int i = 1; i <= m; i++) { //遍历1~m个人 10 if (cnt == m - 1) { //如果已出局m-1人,则最后一人为答案 11 for (int j = 1; j <= m; j++) { 12 if (vis[j] == false) { 13 cout << j << endl; 14 } 15 } 16 return 0; 17 } 18 if (vis[i] == true) { 19 if (i == m) { 20 i = 0; 21 } 22 continue; 23 } else { 24 t++; 25 //cout << i << " " << t << endl; 26 if (t == n) { 27 vis[i] = true; 28 t = 0; 29 cnt++; 30 } 31 } 32 if (i == m) { 33 i = 0; 34 } 35 } 36 return 0; 37 }
原文:https://www.cnblogs.com/fx1998/p/12716158.html