#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int>table;
int n,m;
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++){ //赶走n个人
pos = (pos+m-1)%table.size(); //圆桌是个环,取余处理
table.erase(table.begin()+pos); //赶走坏人,table人数减1
}
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<<endl;
}
return 0;
}
圆桌问题(约瑟夫环)(C/C++实现)
最新推荐文章于 2024-01-23 15:50:05 发布