当前位置:网站首页>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;
}边栏推荐
猜你喜欢

leetcode 47. Permutations II 全排列 II(中等)

单向环形链表实现约瑟夫环

import torch_ Data view of geometric

VGA display color bar and picture (FPGA)

Overview of embedded system 3- development process, learning basis and methods of embedded system

大一女生废话编程爆火!懂不懂编程的看完都拴Q了

Summary of question brushing in leetcode sliding window

移动应用出海的“新大陆”

"New continent" of mobile application going to sea

IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V
随机推荐
Newoj week 10 question solution
leetcode 47. Permutations II full permutations II (medium)
import torch_geometric 的Data 查看
Hardware composition of embedded system - introduction of embedded development board based on ARM
Overview of embedded system 3- development process, learning basis and methods of embedded system
Share PDF HD version, series
verilog-mode的简要介绍
How to solve the problem of data table query error when SQLite writes the registration function?
Embedded system hardware composition - embedded system hardware architecture
403 you don't have permission to access this resource
Stm32f1 and stm32subeide programming example - device driver -dht11 temperature sensor driver
The goods are full. You must take this knowledge
imagemagick:a gentle introduction to magick++
[Title brushing] Super washing machine
list和dict的应用
R language ggplot2 visualization: use the ggrep package to add a number label to the data point at the end of the line plot
[wechat applet development] Part 1: development tool installation and program configuration
智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S
单向环形链表实现约瑟夫环
关于#SQLite写注册功能时,数据表查询出错#的问题,如何解决?