当前位置:网站首页>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
边栏推荐
- 2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
- Use of list - addition, deletion, modification and query
- Go对文件操作
- .105Location
- Crack sliding verification code
- Thirteen documents in software engineering
- Implementation of image recognition code based on VGg convolutional neural network
- C network related operations
- C# 网络相关操作
- Qtablewidget usage explanation
猜你喜欢
How to install jsonpath package
re正则表达式
Re regular expression
Auto. JS custom dialog box
Error in created hook: "referenceerror:" promise "undefined“
[UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)
Data stream encryption and decryption of C
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Examination question bank and online simulation examination of the third batch (main person in charge) of special operation certificate of safety officer a certificate in Guangdong Province in 2022
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
随机推荐
列表的使用-增删改查
Stanford machine learning course summary
Basic usage of crawler requests
Amount input box, used for recharge and withdrawal
YOLOv4剪枝【附代码】
Implementation of image recognition code based on VGg convolutional neural network
Process management command
On the problem of V-IF display and hiding
2022 tea artist (primary) examination simulated 100 questions and simulated examination
C language array processing batch data
k8s之实现redis一主多从动态扩缩容
cartographer_ There is no problem compiling node, but running the bug that hangs directly
Flash operates on multiple databases
Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
2022制冷与空调设备运行操作判断题及答案
Special effects case collection: mouse planet small tail
Identification verification code
On the method of outputting the complete name of typeID from GCC
C1 notes [task training chapter I]