当前位置:网站首页>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
边栏推荐
- [UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
- JS forms the items with the same name in the array object into the same array according to the name
- 读取excel,int 数字时间转时间
- ES6
- 2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
- cv_ Solution of mismatch between bridge and opencv
- Go's gin framework learning
- _ FindText error
- Go file operation
- Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
猜你喜欢
随机推荐
Tensorflow tensor introduction
.104History
Data stream encryption and decryption of C
Climbing watermelon video URL
C byte array (byte []) and string are converted to each other
Submit local warehouse and synchronize code cloud warehouse
C network related operations
高德地图搜索、拖拽 查询地址
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
Classification of cifar100 data set based on convolutional neural network
开源按键组件Multi_Button的使用,含测试工程
Go语言JSON包使用
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
极致体验,揭晓抖音背后的音视频技术
Secure credit
Svn simple operation command
QTableWidget使用讲解
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
Nat commun | current progress and open challenges of applied deep learning in Bioscience









