当前位置:网站首页>围圈报数(北理工机试题)(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 13th day notes

Plato Farm通过LaaS协议Elephant Swap,为社区用户带来全新体验

An error in the fourth edition of the red book?

Cuteone: a onedrive multi network disk mounting program / with member / synchronization and other functions

单例模式(双检锁)

How to use devaxpress WPF to create the first MVVM application in winui?
软件测试面试常见问题及答案(发散思维、接口、性能、概念、)

The EXE compiled by QT is started with administrator privileges

win10/win11无损扩大C盘空间,跨盘合并C、E盘

Arduinouno drive RGB module full color effect example
随机推荐
1.28亿美元!芬兰量子计算公司IQM获世界基金支持
How to use devaxpress WPF to create the first MVVM application in winui?
Skywalking系列学习之告警通知源码分析
Complete source code of mall applet project (wechat applet)
LabVIEW中编程更改进程的优先级
How to visit the latest version of burpsuite pro in vain
Debezium series: the binlog file cannot be recovered after the record is hung from the library server, and the task is switched to the main library to ensure that the data is not lost
coco test-dev 测试代码
ZJCTF_login
AcWing 2074. 倒计数 模拟
[栈和队列简单题] LeetCode 232. 用栈实现队列,225. 用队列实现栈
cocos小游戏实战-05-NPC与角色攻击逻辑
MarqueeView实现滑动展示效果
毕业2年转行软件测试获得12K+,不考研月薪过万的梦想实现了
身家破亿!86版「红孩儿」拒绝出道成学霸,已是中科院博士,名下52家公司
数模1232
CS224W fall 课程 ---- 1.1 why Graphs ?
Inftnews | ggac and China Aerospace ases exclusively produce "China 2065 Collection Edition"
用最原始的方法纯手工实现常见的 20 个数组方法
After two years of graduation, I switched to software testing and got 12k+, and my dream of not taking the postgraduate entrance examination with a monthly salary of more than 10000 was realized