编程介的小学生 2017-07-21 16:05 采纳率: 20.3%
浏览 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 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解