当前位置:网站首页>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
边栏推荐
- Romance in C language
- 纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
- Re expression régulière
- Cloud native Virtualization: building edge computing instances based on kubevirt
- Welcome to the markdown editor
- mysql自动启动设置用Systemctl start mysqld启动
- 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
- Halo open source project learning (II): entity classes and data tables
- k8s之实现redis一主多从动态扩缩容
- On the problem of V-IF display and hiding
猜你喜欢

Solving the problem of displaying too many unique values in ArcGIS partition statistics failed

Chrome浏览器的跨域设置----包含新老版本两种设置

Detailed deployment of flask project

.105Location
![Yolov4 pruning [with code]](/img/09/ea4376d52edb7e419ace2cb1e0356b.gif)
Yolov4 pruning [with code]

2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
![[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader](/img/45/f9e24ae1c619f78aeeb7bcf12d6e5f.png)
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader

高德地图搜索、拖拽 查询地址

Classification of cifar100 data set based on convolutional neural network

mysql自动启动设置用Systemctl start mysqld启动
随机推荐
C# 网络相关操作
Selenium + phantom JS crack sliding verification 2
Crawl the product data of cicada mother data platform
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
Flash - Middleware
云原生虚拟化:基于 Kubevirt 构建边缘计算实例
Qtablewidget usage explanation
开源按键组件Multi_Button的使用,含测试工程
Gaode map search, drag and drop query address
Fashion classification case based on keras
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
.105Location
C1 notes [task training part 2]
Classes and objects
C byte array (byte []) and string are converted to each other
Chrome浏览器的跨域设置----包含新老版本两种设置
Secure credit
Flask项目的部署详解
2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination