当前位置:网站首页>猴子选大王
猴子选大王
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];
}
边栏推荐
- 【 application 】 life many years of operations, what turned scored 12 k + annual bonus salary?
- Redis笔记基础篇:6分钟看完Redis的八种数据类型
- Dynamic proxy tool class
- np.isnan ()
- Phospholipid-polyethylene glycol-azide, DSPE-PEG-Azide, DSPE-PEG-N3, MW: 5000
- C语言 结构体定义方法
- IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
- MySQL中字符串比较大小(日期字符串比较问题)
- The difference between the knowledge question and answer session with the knowledge
- 远程调试、无cuDnn、自定义模块无法导入问题记录
猜你喜欢

npm--package.json---require

Error in render: “TypeError: Cannot read properties of null (reading ‘0‘)“ 报错解决方案

科研试剂DMPE-PEG-Mal 二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺
[email protected]在static属性上的使用"/>@Autowired详解[email protected]在static属性上的使用

Debian 10 NTP Service Configuration

MySQL分库分表

mysql中如何查看表是否被锁

啃瓜记录又一天

UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu

新工程加载YOLOV6的预训练权重问题
随机推荐
Knowledge Engineering Assignment 2: Introduction to Knowledge Engineering Related Fields
动态代理工具类
Monaco Editor 的基本用法
__dirname
MySQL分页查询的5种方法
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/yolov5-5.0/models/commo
debian 10 nat 与路由转发
C语言的变长数组
UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu
解决glob()返回文件排序不一致问题&onnx本地按照安装方法
yolov5调用ip摄像头时出现的问题
磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
parser = argparse.ArgumentParser()解析
JJWT工具类
kettle 安装与配置
磷脂-聚乙二醇-靶向新生血管靶向肽APRPG,DSPE-PEG-APRPG
错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:
The usage of json type field in mysql
np.isnan()
docker 安装 sqlserver中的坑点