社区讨论

到底哪里的问题?

P1996约瑟夫问题参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lo1hp38i
此快照首次捕获于
2023/10/22 21:13
2 年前
此快照最后确认于
2023/11/02 21:50
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;

int n,m;
queue <int> q;

int main(){
	
	cin>>n>>m;
	
	for(int i=1;i<=m-1;i++){
		q.push(i);
	}
	
	while(!q.empty()){
		for(int i=1;i<=m-1;++i){
			q.push(q.front());
			q.pop();
//			int x=q.front();
//			q.pop();
//			q.push(x);
		}
		
		if(q.front()==m){
			cout<<q.front()<<" ";
			q.pop();
		}
		
		}
		
	return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...