当前位置:网站首页>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;
}
边栏推荐
- 使用cpolar发布树莓派网页(apache2网页的发布)
- 35道MySQL面试必问题图解,小白都能看懂
- Redis configuration file explanation
- Analysis vulnerability introduction
- Deploy flask on Alibaba cloud server
- Solve blast database error: error pre fetching sequence data
- 知识产权相关的风险评估要怎么做
- JS learning notes 24-28: end
- PS how to crop photos
- 使用cpolar发布树莓派网页(apache2的安装测试)
猜你喜欢

Application of edge technology and applet container in smart home

Introduction to mqtt protocol

MLX90640 红外热成像仪传感器模块开发笔记(八)

Mlx90640 infrared thermal imager sensor module development notes (VIII)

PHP memory horse

charles如何安装并使用
![SQL error [1810] [22008]: ora-01810: format code occurs twice](/img/3b/4cbc0efe23f6f71163a115cd098ea9.png)
SQL error [1810] [22008]: ora-01810: format code occurs twice

On July 29, apachecon | apachepulsar's exploration and practice in vivo will be broadcast soon

边缘技术和小程序容器在智能家居中的应用

Examples of Pareto optimality and Nash equilibrium
随机推荐
Foundation of knowledge atlas (II) - knowledge expression system of knowledge atlas
RepVGG论文详解以及使用Pytorch进行模型复现
Compilation language and interpretation language
SQL labs detailed problem solving process (less1-less10)
C language exercises
14、 ROS meta function package
2、 Declaration and definition of variables and constants
2021-09-02
手摸手实现Canal如何接入MySQL实现数据写操作监听
iPhone苹果手机上一些不想让他人看到的APP应用图标怎么设置手机桌面上的APP应用设置隐藏不让显示在手机桌面隐藏后自己可以正常使用的方法?
Talk about low code / zero code tools
QT serialization qdatastream
Third class exercise
PHP memory horse
Compose learning notes 2 - launchedeffect, status and status management
5、 C language judgment statement
Rocky基础之修改网卡名为eth0
RPC (remote procedure call protocol) telecommunication framework
Buuctf partial solution
PHP magic method