当前位置:网站首页>猴子选大王(约瑟环问题)
猴子选大王(约瑟环问题)
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];
}
边栏推荐
- debian 10 nat 与路由转发
- C语言的变长数组
- np.isnan ()
- docker 安装 sqlserver中的坑点
- Chemical reagent Phospholipid-polyethylene glycol-hydroxyl, DSPE-PEG-OH, DSPE-PEG-Hydroxyl, MW: 5000
- 【手把手带你学nRF52832/nRF52840 · (1)开发环境搭建】
- 广州华为面试总结
- require模块化语法
- 3 minutes to take you to understand WeChat applet development
- The difference between the knowledge question and answer session with the knowledge
猜你喜欢

kettle 安装与配置

ModuleNotFoundError No module named ‘xxx‘可能的解决方案大全

Redis simple study notes

Problems when yolov5 calls ip camera

【装机】老毛桃的安装及使用

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

Debian 10 NTP 服务配置

DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent

@Configuration详解

配置mmdet来训练Swin-Transformer之一配置环境
随机推荐
3分钟带你了解微信小程序开发
Cut out web icons through PS 2021
sh: 1: curl: not found
针对简历上的问题
【装机】老毛桃的安装及使用
@Configuration详解
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
parser = argparse.ArgumentParser() parsing
Error in render: “TypeError: Cannot read properties of null (reading ‘0‘)“ 报错解决方案
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
The difference between the knowledge question and answer session with the knowledge
如何查看一个现有的keil工程之前由什么版本的keil IDE编译
磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
JJWT工具类
Error: with open(txt_path,'r') as f: FileNotFoundError: [Errno 2] No such file or directory:
getattr()函数解析
这些JS题面试时一定要答对!
C语言 结构体定义方法
MySQL中JOIN的用法
js 取字符串中某位置某特征的值,如华为(Huawei)=>华为