当前位置:网站首页>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
边栏推荐
- QTableWidget使用讲解
- Using files to save data (C language)
- 列表的使用-增删改查
- 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
- Encapsulate a timestamp to date method on string prototype
- C language loop structure program
- Utilisation de la liste - Ajouter, supprimer et modifier la requête
- Implementation of k8s redis one master multi slave dynamic capacity expansion
- [appium] write scripts by designing Keyword Driven files
- Add animation to the picture under V-for timing
猜你喜欢
Operation of 2022 mobile crane driver national question bank simulation examination platform
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
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
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)
GDAL + ogr learning
SystemVerilog (VI) - variable
C network related operations
Summary of floating point double precision, single precision and half precision knowledge
Jenkspy package installation
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
随机推荐
Notes on common basic usage of eigen Library
Operation of 2022 mobile crane driver national question bank simulation examination platform
Remember using Ali Font Icon Library for the first time
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
油猴网站地址
On the method of outputting the complete name of typeID from GCC
Re expression régulière
C1小笔记【任务训练篇二】
JS high frequency interview questions
Crack sliding verification code
C1 notes [task training chapter I]
C language loop structure program
Implementation of k8s redis one master multi slave dynamic capacity expansion
Uniapp custom search box adaptation applet alignment capsule
Map basemap Library
Fashion classification case based on keras
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
Error in created hook: "referenceerror:" promise "undefined“
word frequency count
高德地图搜索、拖拽 查询地址