编程介的小学生 2017-07-21 16:05 采纳率: 20.5%
浏览 704
已采纳

Josephus Again

Problem Description
Traditional Joseph problem is n personal circle,from the first one to start to call the number. The number of people m back from the circle out until only left one person so far.
But now, we think about another Josephus problem. At the first, the circle includes n person. From the first one to start to call the number until call the m, we add a person beside the person who calls the number m, and the new person calls the number at the next round. Repeat this process, until k person in the circle. Now, label the n individuals, for the order of 1...n. The new added person label n+1...n+k by order. And we are interest in what the label the person whose rank is p.
To simplify the problem, we only think about when m=1. For example, N=3 and k=12, the circle is changed as follows:

Now ,the first one’s label is 1 and the second is 7,is third is 4,the forth is 8,the fifth is 2,the sixth is 9,the seventh is 5,the eighth
is 10,the ninth is 3,the tenth is 11,the eleventh is 6,the twelfth
is 12.

Input
There many cases.
For every case:

The first line, two integer n(1<=n<=10^9),k(n<k<=10^9),q(1<=q<10^4),
N is the initial person, k is the final number of person, q is the number of query.
Then next q lines, every line contains an integer p as a query.
(1<=p<=k)

Output
For every case:

Total q lines, for every line, output the person’s lable who is now ranked p-th.

Sample Input
3 12 2
3
5

Sample Output
4
2

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-08-05 16:44
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号