当前位置:网站首页>猴子选大王
猴子选大王
2022-08-02 03:22:00 【寒江飞冰】
7-45 猴子选大王 (20分)
一群猴子要选新猴王。新猴王的选择方法是:让N只候选猴子围成一圈,从某位置起顺序编号为1~N号。从第1号开始报数,每轮从1报到3,凡报到3的猴子即退出圈子,接着又从紧邻的下一只猴子开始同样的报数。如此不断循环,最后剩下的一只猴子就选为猴王。请问是原来第几号猴子当选猴王?
输入格式:
输入在一行中给一个正整数N(≤1000)。
输出格式:
在一行中输出当选猴王的编号。
输入样例:
11
输出样例:
7
// #include <stdio.h>
// int main()
// {
// int n,i,s=0;
// scanf("%d",&n);
// ///s表示最后一只猴子(猴大王)在每轮(先倒数第1轮,再求倒数第二轮,...)中自己的序号
// //i表示倒数第i次排序
// for(i=2 ; i<=n ; i++)
// s = (s+3) % i ;//报数为3即为要删除的猴子 ,取余i是为了映射每一轮猴大王的序号
// printf("%d\n",s+1);
// return 0 ;
// }
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int>a;
for(int i=0;i<n;i++)
{
a.push_back(i+1);
}
int num=0;
while(a.size()!=1)
{
for(int i=0;i<a.size();i++)
{
num++;
if(num==3)
{
a.erase(a.begin()+i);
if(a.begin()+i!=a.end())
{
num=1;
}
else
{
num=0;
}
}
}
}
cout<<a[0];
}
边栏推荐
- Cut out web icons through PS 2021
- Mysql8.0安装教程
- 语义分割标签即像素值的巨坑,transforms.ToTensor()的错误使用
- ModuleNotFoundError No module named ‘xxx‘可能的解决方案大全
- 基本运算符
- 第一篇博客
- C语言入门小游戏—三子棋
- DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine supply, MW: 5000
- DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent
- mysql创建表
猜你喜欢

通过PS 2021 将网页图标抠下来

ThunderBirde无法登录问题、pycharm调试一直收集数据、RuntimeError: CUDA error: device-side assert triggered等疑难杂症解决

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

网址URL

@Configuration详解

Mysql8创建用户以及赋权操作

parser = argparse.ArgumentParser() parsing

nucleo stm32 h743 FREERTOS CUBE MX配置小记录

Debian 10 NTP 服务配置

磷脂-聚乙二醇-靶向新生血管靶向肽APRPG,DSPE-PEG-APRPG
随机推荐
require模块化语法
SSM integration
String comparison size in MySQL (date string comparison problem)
Error: with open(txt_path,'r') as f: FileNotFoundError: [Errno 2] No such file or directory:
querystring模块
Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
如何查看一个现有的keil工程之前由什么版本的keil IDE编译
SOCKS5
活体检测 Adaptive Normalized Representation Learning for GeneralizableFace Anti-Spoofing 阅读笔记
__dirname
广州华为面试总结
npm--package.json---require
oracle inner join and outer join
小程序 van-cell 换行能左对齐问题
mysql中json类型字段用法
mysql中如何查看表是否被锁
DSPE-PEG-DBCO 磷脂-聚乙二醇-二苯并环辛炔 一种线性杂双官能聚乙二醇化试剂
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
np.unique() function