21933_InDanger

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

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

Pro.ID

21933

Title

In Danger

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    Flavius Josephus and 40 fellow rebels were trapped by the Romans. His companions preferred suicide to surrender, so they decided to form a circle and to kill every third person and to proceed around the circle until no one was left. Josephus was not excited by the idea of killing himself, so he calculated the position to be the last man standing (and then he did not commit suicide since nobody could watch).

    We will consider a variant of this "game" where every second person leaves. And of course there will be more than 41 persons, for we now have computers. You have to calculate the safe position. Be careful because we might apply your program to calculate the winner of this contest!

    输入

    The input contains several test cases. Each specifies a number n, denoting the number of persons participating in the game. To make things more difficult, it always has the format "xyez" with the following semantics: when n is written down in decimal notation, its first digit is x, its second digit is y, and then follow z zeros. Whereas 0 ≤ x, y ≤ 9, the number of zeros is 0 ≤ z ≤ 6. You may assume that n > 0. The last test case is followed by the string 00e0.

    输出

    Description

    Flavius Josephus and 40 fellow rebels were trapped by the Romans. His companions preferred suicide to surrender, so they decided to form a circle and to kill every third person and to proceed around the circle until no one was left. Josephus was not excited by the idea of killing himself, so he calculated the position to be the last man standing (and then he did not commit suicide since nobody could watch).

    We will consider a variant of this "game" where every second person leaves. And of course there will be more than 41 persons, for we now have computers. You have to calculate the safe position. Be careful because we might apply your program to calculate the winner of this contest!

    Input

    The input contains several test cases. Each specifies a number n, denoting the number of persons participating in the game. To make things more difficult, it always has the format "xyez" with the following semantics: when n is written down in decimal notation, its first digit is x, its second digit is y, and then follow z zeros. Whereas 0 ≤ x, y ≤ 9, the number of zeros is 0 ≤ z ≤ 6. You may assume that n > 0. The last test case is followed by the string 00e0.

    Output

    For each test case generate a line containing the position of the person who survives. Assume that the participants have serial numbers from 1 to n and that the counting starts with person 1, i.e., the first person leaving is the one with number 2. For example, if there are 5 persons in the circle, counting proceeds as 2, 4, 1, 5 and person 3 is staying alive.

    Sample Input

    05e0
    01e1
    42e0
    66e6
    00e0

    Sample Output

    3
    5
    21
    64891137

    Source

    样例输入

    05e0
    01e1
    42e0
    66e6
    00e0

    样例输出

    3
    5
    21
    64891137

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部