当前位置:网站首页>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;
}边栏推荐
- 442个作者100页论文!谷歌耗时2年发布大模型新基准BIG-Bench | 开源
- 【云原生 | Kubernetes篇】深入了解Deployment(八)
- Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
- leetcode 47. Permutations II 全排列 II(中等)
- Five ways to quickly download large files from Google cloud disk
- 单向环形链表实现约瑟夫环
- 创新实训(十一)开发过程中的一些bug汇总
- 软件构造 03 正则表达式
- Pre research of image scanning tool
- verilog-mode的简要介绍
猜你喜欢

C#DBHelper_ FactoryDB_ GetConn

import torch_geometric 的Data 查看

A "murder case" caused by ES setting operation
![[wechat applet development] Part 1: development tool installation and program configuration](/img/a8/f4dcbde295ba7cf738d878464b3af0.png)
[wechat applet development] Part 1: development tool installation and program configuration

Share PDF HD version, series

leetcode 47. Permutations II full permutations II (medium)

Overview of embedded system 1- definition, characteristics and development history of embedded system

【刷题篇】抽牌获胜的概率

unittest框架

Pytoch official fast r-cnn source code analysis (I) -- feature extraction
随机推荐
The goods are full. You must take this knowledge
torch_geometric message passing network
Will the next star of PPT for workplace speech be you [perfect summary] at the moment
Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
R language ggplot2 visualization: use the ggrep package to add a number label to the data point at the end of the line plot
位图、布隆过滤器和哈希切分
[brush title] probability of winning a draw
【刷题篇】超级洗衣机
Pytoch official fast r-cnn source code analysis (I) -- feature extraction
Successful job hopping Ali, advanced learning
torch_ geometric message passing network
VGA display color bar and picture (FPGA)
import torch_ Geometric loads some common datasets
leetcode 47. Permutations II 全排列 II(中等)
Redis消息队列重复消费问题
Stm32f1 and stm32cubeide programming examples - device driver -eeprom-at24c256 driver
Structure matérielle du système embarqué - introduction du Conseil de développement embarqué basé sur arm
import torch_geometric 的Data 查看
Pre research of image scanning tool
智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S