当前位置:网站首页>猴子选大王(约瑟环问题)
猴子选大王(约瑟环问题)
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];
}
边栏推荐
- FreeRTOS内核详解(1) —— 临界段保护原理
- [Mianjing] Mihayou data development on one side and two sides
- 动态代理工具类
- Error: with open(txt_path,'r') as f: FileNotFoundError: [Errno 2] No such file or directory:
- DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰活性基团
- SSM整合
- sh: 1: curl: not found
- 【我的创作纪念日】 3周年
- 磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
- 第一篇博客
猜你喜欢

DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰活性基团

云服务器安装部署Nacos2.0.4版本

利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置

Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide

String comparison size in MySQL (date string comparison problem)

PCL—点云数据分割

Phospholipid-polyethylene glycol-thiol, DSPE-PEG-Thiol, DSPE-PEG-SH, MW: 5000

require模块化语法

一个结构体 = 另一个结构体(同类型结构体之间可直接赋值操作)

Debian 10 NTP Service Configuration
随机推荐
STM32 触发HardFault_Handler如何查找原因
Source Insight 使用教程(2)——常用功能
科研试剂DMPE-PEG-Mal 二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺
STM32 map文件解析
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
远程调试、无cuDnn、自定义模块无法导入问题记录
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
getattr()函数解析
@Autowired与@Resource区别
【手把手带你学nRF52832/nRF52840 · (1)开发环境搭建】
磷脂-聚乙二醇-醛基 DSPE-PEG-Aldehyde DSPE-PEG-CHO MW:5000
【装机】老毛桃的安装及使用
np.unique()函数
新工程加载YOLOV6的预训练权重问题
Basic usage of Monaco Editor
活体检测 Adaptive Normalized Representation Learning for GeneralizableFace Anti-Spoofing 阅读笔记
C语言入门小游戏—三子棋
Amazon sellers how to improve the conversion
Phospholipid-polyethylene glycol-thiol, DSPE-PEG-Thiol, DSPE-PEG-SH, MW: 5000