当前位置:网站首页>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;
}
边栏推荐
- 2021-09-02
- Machine learning related concepts
- 18、 ROS topic name setting
- SQL learning
- 21、 TF coordinate transformation (I): coordinate MSG message
- Robot mathematics foundation 3D space position representation space position
- The automatic prompt of vs code code is missing - a tick to solve it
- Image steganography method
- Modify the default path of Jupiter notebook
- JS study notes 18-23
猜你喜欢

Introduction to MITK

Compilation failure caused by kotlin version upgrade

Establishment and traversal of binary tree (implemented in C language)

Compose learning notes 1-compose, state, flow, remember

JS学习笔记18-23

Application of edge technology and applet container in smart home

Read the introduction tutorial of rainbow

The automatic prompt of vs code code is missing - a tick to solve it

VTK notes - picker picker summary

35道MySQL面试必问题图解,小白都能看懂
随机推荐
JS -- realize the rotation chart (complete function)
iframe 标签
Using keras to visualize the network model, failed to import pydot appears
3、 C language storage class
Solution to the problem of high collapse caused by float (including all methods)
Hard disk partition method
First class exercise
Compilation language and interpretation language
PS modify the length and width pixels and file size of photos
17、 Solutions to duplicate names of ROS function packages and nodes
Is the expansion operator a deep copy or a shallow copy
Instant experience | further improve application device compatibility with cts-d
Talk about low code / zero code tools
The modified network card name of rocky foundation is eth0
@DS('slave') 多数据源兼容事务问题解决方案
为什么企业需要用户自治的数字身 份
Namespace conflict problem
2021-09-02
MLX90640 红外热成像仪传感器模块开发笔记(八)
Tensorflow GPU installation process record