当前位置:网站首页>Queue solving Joseph problem
Queue solving Joseph problem
2022-04-23 18:00:00 【Round programmer】
queue Queue The addition of data occurs at the end , The removal of data occurs at the head end
There is only one exit and one entrance
First-in First-out, FIFO
example , Operating system process scheduling ,I/O buffer
class Queue:
def __init__(self):
self.items = []
def idEmpty(self):
return self.items == []
def enqueue(self,item):
self.items.insert(0,item)
def dequeue(self):
return self.items.pop()
def size(self):
return len(self.items)
Joseph's question
N A circle of individuals , Count from the first person , To report for duty M People out of circles ,
The rest of us went on from 1 Start counting , To report for duty M People out of circles ; So back and forth , Until everyone goes out of the circle
def Joseph(nameList,num):
simqueue = Queue()
for name in nameList:
simqueue.enqueue(name)
while simqueue.size() > 1 :
for i in range(num):
simqueue.enqueue(simqueue.dequeue())
simqueue.dequeue()
return simqueue.dequeue()
print(Joseph([" Zhao er ", " Zhang San ", " Li Si ", " Wang Wu ", " Qian Liu ", " Sun Qi "], 7))
版权声明
本文为[Round programmer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545315637.html
边栏推荐
- Calculation of fishing net road density
- Go language JSON package usage
- Basic usage of crawler requests
- Notes on common basic usage of eigen Library
- ES6
- An example of linear regression based on tensorflow
- Nanotechnology + AI enabled proteomics | Luomi life technology completed nearly ten million US dollars of financing
- Auto.js 自定义对话框
- C# 的数据流加密与解密
- C1小笔记【任务训练篇二】
猜你喜欢

Process management command

Uniapp custom search box adaptation applet alignment capsule

Flask项目的部署详解

Gaode map search, drag and drop query address
![[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)](/img/74/bb173ca53d62304908ca80d3e96939.png)
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)

JS high frequency interview questions

Data stream encryption and decryption of C

Welcome to the markdown editor

Tell the truth of TS

Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
随机推荐
Build openstack platform
Using files to save data (C language)
Cross domain settings of Chrome browser -- including new and old versions
Clion installation tutorial
Generate verification code
positioner
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
C# 的数据流加密与解密
journal
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
JS high frequency interview questions
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
Timestamp to formatted date
QTableWidget使用讲解
Romance in C language
word frequency count
[appium] write scripts by designing Keyword Driven files
Svn simple operation command
油猴网站地址
C [file operation] read TXT text by line