21805_JosephusAgain

2022-5-16 18:20| 发布者: Hocassian| 查看: 25| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505863625699-Problem List-采集的数据-后羿采集器.html

Pro.ID

21805

Title

Josephus Again

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21805

AC

10

Submit

27

Ratio

37.04%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    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.

    输入

    There many cases.

    For every case:

    The first line, two integer n ( 1≤ n ≤ 109 ), k ( n < k ≤ 109 ), q ( 1 ≤ q <104 ), 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 ≤ pk )

    输出

    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 ≤ 109 ), k ( n < k ≤ 109 ), q ( 1 ≤ q <104 ), 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 ≤ pk )

    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

    Hint

    Hint:

    m is always 1.

    Source

    样例输入

    3 12 2
    3
    5

    样例输出

    4
    2

    提示

    Hint:

    m is always 1.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部