Love丶FFC's Blog

CCF-CSP_20171202:游戏

2019-11-29 09:30:38
阅读:762   •   评论:11
标签:,

问题描述

n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向。

游戏开始,从1号小朋友开始顺时针报数,接下来每个小朋友的报数是上一个小朋友报的数加1。若一个小朋友报的数为k的倍数或其末位数(即数的个位)为k,则该小朋友被淘汰出局,不再参加以后的报数。当游戏中只剩下一个小朋友时,该小朋友获胜。
  例如,当n=5, k=2时:
  1号小朋友报数1;
  2号小朋友报数2淘汰;
  3号小朋友报数3;
  4号小朋友报数4淘汰;
  5号小朋友报数5;
  1号小朋友报数6淘汰;
  3号小朋友报数7;
  5号小朋友报数8淘汰;
  3号小朋友获胜。

给定nk,请问最后获胜的小朋友编号为多少?

输入格式

输入一行,包括两个整数nk,意义如题目所述。

输出格式

输出一行,包含一个整数,表示获胜的小朋友编号。

样例输入

5 2

样例输出

3

样例输入

7 3

样例输出

4

数据规模和约定

对于所有评测用例,1 ≤ n ≤ 1000,1 ≤ k ≤ 9。

编程语言:Python

解题思想:

1.这个游戏是平常很容易接触的游戏,因此可以模拟游戏流程

2.模拟一次在现实生活中玩这个游戏的过程,创建一个列表来保存能够继续游戏的人

3.每当淘汰一个人时就从列表中删除该编号,此时剩下的人的位置就往前移动一位,因此就算有人被淘汰,游戏也必须就地继续

时间复杂度:O(n)

IDE代码如下:

  1. NOP, LuckyDigital = map(int, input().split()) # 输入小朋友的人数和淘汰数字
  2. Child = [int(i) for i in range(1, NOP + 1)] # 还剩下的小朋友
  3. Digital = 1 # 报数
  4. i = 0 # 用于循环
  5. while Child.__len__() > 1: # 游戏人数大于1人
  6. SingleDigit = int(str(Digital)[str(Digital).__len__() - 1]) # 获取个位数
  7. if Digital % LuckyDigital == 0 or SingleDigit == LuckyDigital: # 如果符合被淘汰的规则
  8. Child.remove(Child[i]) # 将该小朋友淘汰
  9. else: # 不被淘汰,继续游戏
  10. i += 1 # 继续报数
  11. if i == Child.__len__(): # 报完一圈
  12. i = 0 # 从头开始
  13. Digital += 1 # 累计报数的数字
  14. print(Child[0])

评论板

共有 11 条评论

  1. engarma

    Clematis and the large flowered hybrids are divided into categories group 1, group 2, and group 3 cialis buy online

  2. jordans for cheap

    Read reviews and was a little hesitant since I had already inputted my order. in addition to but thank god, I had no issues. particularly the received item in a timely matter, they are in new condition. in either case so happy I made the purchase. Will be definitely be purchasing again.
    jordans for cheap https://www.cheapjordansstore.com/

  3. cheap jordans

    Read reviews and was a little hesitant since I had already inputted my order. otherwise but thank god, I had no issues. most notably the received item in a timely matter, they are in new condition. situation so happy I made the purchase. Will be definitely be purchasing again.
    cheap jordans https://www.cheapauthenticjordanshoes.com/

  4. louis vuitton outlet sale online

    Read reviews and was a little hesitant since I had already inputted my order. while well as but thank god, I had no issues. decline received item in a timely matter, they are in new condition. in either case so happy I made the purchase. Will be definitely be purchasing again.
    louis vuitton outlet sale online https://www.louisvuittonsoutletonline.com/

  5. authentic cheap jordans

    Read reviews and was a little hesitant since I had already inputted my order. or perhaps but thank god, I had no issues. decline received item in a timely matter, they are in new condition. blue jays so happy I made the purchase. Will be definitely be purchasing again.
    authentic cheap jordans https://www.realjordansretro.com/

  6. Preliaf

    buy cialis usa In addition, maintaining a healthy diet that provides plenty of protein, iron, and vitamins is one of the best ways to flush unwanted fluids from your body

  7. Preliaf

    Monitor Closely 1 enzalutamide will decrease the level or effect of levamlodipine by affecting hepatic intestinal enzyme CYP3A4 metabolism cheapest finasteride on the web

  8. RoEHNfAs

    vardenafil cheap 5 10 mg Approved for use in 2002

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:491232