当前位置:网站首页>猴子选大王(约瑟环问题)
猴子选大王(约瑟环问题)
2022-08-02 03:22:00 【寒江飞冰】
输入
输入两个整数n,m (1<=m,n<=100)
输出
输出一行n个整数,按顺序输出每个出圈人的编号
样例输入
10 3
样例输出
3 6 9 2 7 1 8 5 10 4
#include<iostream>
using namespace std;
int main()
{
int Ring[100];
int length;
cin>>length;
for(int i=0;i<length;i++)
{
Ring[i]=i+1;
}
int n;
cin>>n;
int index=0;
while(length!=1)
{
index=(index+n-1)%length;
cout<<Ring[index]<<" ";
for(int j=index+1;j<=length-1;j++)
{
Ring[j-1]=Ring[j];
}
length--;
}
cout<<Ring[0];
}
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int>Ring;
int length;
cin>>length;
for(int i=0;i<length;i++)
{
Ring.push_back(i+1);
}
int index=0;
int n;
cin>>n;
while(Ring.size()!=1)
{
index=(index+n-1)%Ring.size();
cout<<Ring[index]<<" ";
Ring.erase(Ring.begin()+index);
}
cout<<Ring[0];
}
边栏推荐
- DSPE-PEG-DBCO 磷脂-聚乙二醇-二苯并环辛炔 一种线性杂双官能聚乙二醇化试剂
- Cloud server installation and deployment of Nacos 2.0.4 version
- DOM操作---放大镜案例
- parser = argparse.ArgumentParser() parsing
- 远程调试、无cuDnn、自定义模块无法导入问题记录
- parser = argparse.ArgumentParser()解析
- COCO数据集训练TPH-YoloV5
- basic operator
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/yolov5-5.0/models/commo
- @Configuration详解
猜你喜欢
随机推荐
Detailed explanation of the usage of exists in mysql
Week 7 Review
UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu
排序学习笔记(二)堆排序
getattr() function analysis
Phospholipid-polyethylene glycol-azide, DSPE-PEG-Azide, DSPE-PEG-N3, MW: 5000
js 数组去重的常用方法
C语言入门小游戏—三子棋
基本运算符
Usage of JOIN in MySQL
MySQL中字符串比较大小(日期字符串比较问题)
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
STM32 触发HardFault_Handler如何查找原因
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group
3 minutes to take you to understand WeChat applet development
UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the index ing argu
Amazon sellers how to improve the conversion
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
require模块化语法
SSM整合