You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
873 B

2 years ago
#### 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]<<" ";
```