题解在代码里~
#include#include #include using namespace std;int main(){ int n, k, f[100]; n = 12; cin>>k; //链表做法,复杂度O(n*k) list L; for(int i = 1; i <= n; i++) f[i] = i, L.push_back(i); list ::iterator pos = L.begin(); while(L.size() > 1) { for(int i = 1; i < k; i++) { ++pos; if(pos == L.end()) pos = L.begin(); } f[*pos] = 0; pos = L.erase(pos); if(pos == L.end()) pos = L.begin(); for(int i = 1; i <= n; i++) cout<
<