Files
python/TangDou/LanQiaoBei/LanQiaoBei13GuoSai/约瑟夫环.md
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

52 lines
873 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#### 1、约瑟夫环可以使用队列来模拟。
> 测试用例:
5 3 3
> 答案:
2 4 5 7 8
#### 2、输入 x,y,k 怎么理解?x:男生人数,y:女生人数,k:走到几出列,比如3
```c++
cin>>x>>y>>k;
```
#### 3、队列初始化
```c++
queue<int> q;
balabala
```
#### 4、操作队列
```c++
int cnt=0;
while(剩余x个位置){
auto t=q.front();
q.pop();
cnt++;
balabala
是k的倍数,则干掉,不重新入队列,否则重新入队列 balabala
}
```
#### 5、输出男同学的位置
```c++
while(队列不空){
auto t=q.front();
q.pop();
输出弹出的位置号
balabala
}
```
#### 6、需要排序
```c++
int a[N],idx;
while(q.size()){
auto t=q.front();
q.pop();
a[++idx]=t;
}
sort(a+1,a+1+x);
for(int i=1;i<=x;i++>)
cout<<a[i]<<" ";
```