当前位置:网站首页>围圈报数(北理工机试题)(DAY 83)
围圈报数(北理工机试题)(DAY 83)
2022-07-27 01:06:00 【张学恒】
1:题目
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
时/空限制:1s / 64MB
总通过数:916
总尝试数:1403
北京理工大学考研机试题
2:代码实现
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 55;
int n;
int ne[N];
int main()
{
int T;
cin >> T;
while (T -- )
{
cin >> n;
for (int i = 1; i < n; i ++ ) ne[i] = i + 1;
ne[n] = 1;
int p = n;
for (int i = 0; i < n; i ++ )
{
p = ne[ne[p]];
cout << ne[p] << ' ';
ne[p] = ne[ne[p]];
}
cout << endl;
}
return 0;
}
边栏推荐
- HCIP第十三天笔记
- 次轮Okaleido Tiger即将登录Binance NFT,引发社区热议
- Plato Farm全新玩法,套利ePLATO稳获超高收益
- 力扣(LeetCode)207. 课程表(2022.07.26)
- Portraiture5全新升级版磨皮滤镜插件神器
- Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
- 【flask】服务端获取客户端请求的文件
- The most complete basic knowledge of software testing in the whole network (a must for beginners)
- 积分发放带给商家的两个帮助
- [Ryu] common problems and solutions in installing Ryu
猜你喜欢

Social wechat applet of fanzhihu forum community

Source code analysis of warning notification for skywalking series learning

185. All employees with the top three highest wages in the Department (mandatory)

一道数学题,让芯片巨头亏了5亿美金!

Alibaba cloud technology expert Yang Zeqiang: Construction of observability on elastic computing cloud

关于url编解码应该选用的函数

OpenTelemetry 在服务网格架构下的最佳实践

Hcip 13th day notes
全网最全的软件测试基础知识整理(新手入门必学)

CS224W fall 课程 ---- 1.1 why Graphs ?
随机推荐
Use the most primitive method to manually implement the common 20 array methods
Complete source code of mall applet project (wechat applet)
商城小程序项目完整源码(微信小程序)
Integrated water conservancy video monitoring station telemetry terminal video image water level water quality water quantity flow velocity monitoring
HCIP第十四天笔记
仿知乎论坛社区社交微信小程序
力扣(LeetCode)207. 课程表(2022.07.26)
【flask】服务端获取客户端请求的文件
HCIP第十三天笔记
全网最全的软件测试基础知识整理(新手入门必学)
Hcip 13th day notes
Boom 3D new 2022 audio enhancement app
Ansible series: do not collect host information gather_ facts: False
Analysis of [paper] pointlanenet papers
子模块cache缓存失效
Cs224w fall course - --- 1.1 why graphs?
Source code analysis of warning notification for skywalking series learning
[SQL simple question] leetcode 627. change gender
196. Delete duplicate email addresses
typora详细教程