当前位置:网站首页>猴子选大王
猴子选大王
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];
}
边栏推荐
- 【面试】失败的一次面试
- DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine supply, MW: 5000
- 云服务器安装部署Nacos2.0.4版本
- [Learning Records of Boxue Valley] Super summary, share with heart | Software Testing Interface Testing Basics
- Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
- nucleo stm32 h743 FREERTOS CUBE MX配置小记录
- debian 10 nat 与路由转发
- ssm各类配置模板
- C语言的变长数组
- The difference between the knowledge question and answer session with the knowledge
猜你喜欢

Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000

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

【程序人生】做了多年的运维,靠什么转行拿下12K+年终奖的薪资?

磷脂-聚乙二醇-靶向新生血管靶向肽APRPG,DSPE-PEG-APRPG

Amazon sellers how to improve the conversion

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

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

DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶供应,MW:5000

Mysql8.0安装教程

mysql卸载详细教程
随机推荐
Amazon sellers how to improve the conversion
第一篇博客
MySQL占用CPU过高,排查原因及解决的多种方式法
__dirname
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
kettle 安装与配置
解决glob()返回文件排序不一致问题&onnx本地按照安装方法
[Learning Records of Boxue Valley] Super summary, share with heart | Software Testing Interface Testing Basics
JJWT tool class
UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰活性基团
磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
跨域问题解决
知识工程作业2:知识工程相关领域介绍
js 取字符串中某位置某特征的值,如华为(Huawei)=>华为
oracle内连接和外连接
COCO数据集训练TPH-YoloV5
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Phospholipid-polyethylene glycol-azide, DSPE-PEG-Azide, DSPE-PEG-N3, MW: 5000
C语言 内联函数