当前位置:网站首页>3559. 围圈报数
3559. 围圈报数
2022-07-28 14:15:00 【追寻远方的人】
N 个人围成一圈顺序编号,从 1 号开始按 1、2、3 顺序报数,报 3 者退出圈外,其余的人再从1、2、3 开始报数,报 3 的人再退出圈外,依次类推。
请按退出顺序输出每个退出人的原序号。
要求使用环行链表编程。
输入格式
第一行包含整数 T,表示共有 T 组测试数据。
每组数据一行,一个整数 N。
输出格式
每组数据输出一行,一个结果,包含每个退出人的原序号,用空格隔开。
数据范围
1≤T≤5,
1≤N≤50
输入样例:
1
4
输出样例:
3 2 4 1
代码:
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main()
{
cin >> m;
while (m--)
{
cin >> n;
int k = 3;
vector<int> res;
list<int> mylist;
list<int>::iterator it;
for (int i = 1; i <= n; i++)
{
mylist.push_back(i);
}
int num = 1;
while (mylist.size())
{
for (it = mylist.begin(); it != mylist.end();)
{
if (num % k == 0)
{
res.push_back(*it);
it = mylist.erase(it);
}
else
it++;
num++;
}
}
for (int i = 0; i < n; i++)
cout << res[i] << " ";
cout << endl;
}
return 0;
}
边栏推荐
猜你喜欢

RepVGG论文详解以及使用Pytorch进行模型复现

Compose learning notes 2 - launchedeffect, status and status management

使用cpolar发布树莓派网页(apache2网页的发布)

JS -- realize the rotation chart (complete function)

Feeling about software development work in the second anniversary

使用cpolar发布树莓派网页(apache2的安装测试)

Mlx90640 infrared thermal imager sensor module development notes (VIII)

Pytorch GPU installation

VTK notes - picker picker summary

A problem -- about dragging div in JS, when I change div to round, there will be a bug
随机推荐
Establishment and traversal of binary tree (implemented in C language)
Three pain points of software development! How to solve the applet container?
CCSP 云安全设计原则都有哪些
QT environment cannot run error set
VTK notes - picker picker summary
Compilation failure caused by kotlin version upgrade
Analysis vulnerability introduction
2021 year end summary of gains and losses
Privacy computing summary
Basic operation implementation of sequence table
Solve blast database error: error pre fetching sequence data
6、 C language circular statement
Downloading PIP package is too slow
Foundation of knowledge atlas (II) - knowledge expression system of knowledge atlas
Idea2020.1.4 packages package collapse
The modified network card name of rocky foundation is eth0
MySQL authorization method
Mysql使用left join连表查询时,因连接条件未加索引导致查询很慢
Talk about low code / zero code tools
JS study notes 18-23