3 solutions
-
0
真好,这个约瑟夫问题不用写队列
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<map> using namespace std; bool vis[100005]; int main(void) { int n, t; cin >> n >> t; int cnt = n; int x = 0; while (cnt) { for (int i = 1; i <= t; i++) { x++; if (x > n) x -= n; while (vis[x] && x <= n) { x++; if (x > n) x -= n; } } if (!vis[x]) { cnt--; vis[x] = true; } cout << x << " "; } return 0; }
Information
- ID
- 301
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 4
- Tags
- # Submissions
- 72
- Accepted
- 35
- Uploaded By