hdu4841 圆桌问题(数组模拟)

【问题描述】
圆桌上围坐着2n个人。其中n个人是好人,另外n个人是坏人。如果从第一个人开始数数,数到第m个人,则立即赶走该人;然后从被赶走的人之后开始数数,再将数到的第m个人赶走……依此方法不断赶走围坐在圆桌上的人。试问预先应如何安排这些好人与坏人的座位,能使得在赶走n个人之后,圆桌上围坐的剩余的n个人全是好人。

【输入】
多组数据,每组数据输入:好人和坏人的人数n(<=32767)、步长m(<=32767);

【输出】
对于每一组数据,输出2n个大写字母,‘G’表示好人,‘B’表示坏人,50个字母为一行,不允许出现空白字符。相邻数据间留有一空行。

【输入样例】
2 3
2 4

【输出样例】
GBBG
BGGB

【算法代码】

#include <bits/stdc++.h>
using namespace std;
 
const int maxn=32767<<1+5;
int flag[maxn];
 
int main() {
	int n,m;
	while(cin>>n>>m) {
		for(int i=1; i<=2*n; i++) flag[i]=1;
		int tot=2*n;
		int cur=0;
		while(tot>n) {
			for(int i=1; i<=2*n; i++) {
				if(!flag[i]) continue;
				if(tot==n) break;
				cur++;
				if(cur==m) {
					flag[i]=0;
					cur=0;
					tot--;
				}
			}
		}
 
		for(int i=1; i<=2*n; i++) {
			if(!flag[i]) cout<<"B";
			else cout<<"G";
 
			if(i%50==0) cout<<endl;
		}
		cout<<endl<<endl;
	}
 
	return 0;
}
 
 
/*
input:
2 3
2 4
output:
GBBG
BGGB
*/


【参考文献】
https://blog.csdn.net/sterben_da/article/details/51171017
https://blog.csdn.net/ngq0273/article/details/97391019
https://blog.csdn.net/bjxqmy/article/details/98348663
https://blog.csdn.net/qq1013459920/article/details/83622880
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值