朴素的约瑟夫问题,用vector处理即可
#include <iostream> #include <vector> using namespace std; //AHOI1999 圆桌问题 类似于约瑟夫问题 vector<int>table; int n, m; int main() { while (cin >> n >> m) { table.clear(); for (int i = 0; i < 2 * n; i++) table.push_back(i); int pos = 0; for (int i = 0; i < n; i++) { pos = (pos + m - 1) % table.size(); //环,取余处理,这一步比较抽象 table.erase(table.begin() + pos); } int j = 0; for (int i = 0; i < 2 * n; i++) { if (!(i % 50) && i) cout << endl; if (j < table.size() && i == table[j]) { j++; cout << "G"; } else { cout << "B"; } } cout << endl; } return 0; }
标签:int,题解,pos,AHOI1999,++,table,圆桌,HDU4841 From: https://www.cnblogs.com/Miya555/p/17586768.html