当前位置:网站首页>The problem of Joseph in Informatics
The problem of Joseph in Informatics
2022-06-12 13:23:00 【Xiao Liu wants to be number one】
2037:【 example 5.4】 Joseph's question
The time limit : 1000 ms Memory limit : 65536 KB
Submission number : 10954 Passing number : 5588
【 Title Description 】
NN A circle of individuals , Count from the first person , Count to MM People out of circles ; Then the next person starts counting , Count to MM People out of circles ;… Output the number of people who circle in turn .
【 Input 】
Input NN and MM.
【 Output 】
Output one line , Number the people in the circle in turn .
【 sample input 】
8 5【 sample output 】
5 2 8 7 1 4 6 3【 Tips 】
【 Data range 】
For all the data ,2≤N,M≤10002≤N,M≤1000.
#include <iostream>
using namespace std;
int main()
{
int m, n, a[1000], i;
cin >> n >> m;
for (i = 0; i < n; i++)
a[i] = i + 1;// Everyone's serial number
int x = 0, y = 0;//x Is the number of people kicked ,y That's the number
i = 0;
while (x < n)
{
if (a[i] != 0)
y++;
if (y == m)
{
a[i] = 0;// After being kicked out, change its serial number to 0
y = 0;
x++;
cout << i + 1 << " ";
}
i++;
if (i == n)i = 0;// Can't write here break, If break, You can only cycle once
}
return 0;
}边栏推荐
- How to adapt the page size when iframe is embedded in a web page
- [EDA] chip layout design: VLSI layout design using electric
- [database] Navicat -- Oracle database creation
- 基于华为云鲲鹏弹性云服务器ECS部署openGauss数据库【这次高斯不是数学家】
- 嵌入式系统硬件构成-基于ARM的嵌入式开发板介绍
- Summary of question brushing in leetcode sliding window
- 微信web开发者工具使用教程,web开发问题
- R language ggplot2 visualization: use the ggrep package to add a number label to the data point at the end of the line plot
- C language [23] classic interview questions [2]
- About paiwen
猜你喜欢

成功定级腾讯T3-2,万字解析

Known as the next generation monitoring system! See how awesome it is

嵌入式系統硬件構成-基於ARM的嵌入式開發板介紹

嵌入式系统概述3-嵌入式系统的开发流程和学习基础、方法

C#DBHelper_FactoryDB_GetConn
![[Title brushing] Super washing machine](/img/f9/0c69afafa8b32afc5df5e91d6af172.png)
[Title brushing] Super washing machine

"New continent" of mobile application going to sea

Realization of Joseph Ring with one-way ring linked list

Bitmap, bloom filter and hash sharding

Unittest framework
随机推荐
Further understanding of the network
Overview of embedded system 2- composition and application of embedded system
Install MySQL database independently on Debian 10
Bitmap, bloom filter and hash sharding
Structure matérielle du système embarqué - introduction du Conseil de développement embarqué basé sur arm
位图、布隆过滤器和哈希切分
torch_geometric mini batch 的那些事
Getting to know blob objects
【云原生 | Kubernetes篇】Kubernetes 网络策略(NetworkPolicy)
[cloud native | kubernetes] kubernetes networkpolicy
STM32F1与STM32CubeIDE编程实例-设备驱动-EEPROM-AT24C256驱动
import torch_geometric 的Data 查看
Dameng database DM8 Windows environment installation
智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S
[brush title] probability of winning a draw
实战 | 巧用位姿解算实现单目相机测距
嵌入式系统概述1-嵌入式系统定义、特点和发展历程
VTK image sequence mouse interactive flipping
Microsoft Word tutorial, how to insert a header or footer in word?
[you code, I fix] whitesource was officially renamed mend