21518_CombinationLock

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

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

Pro.ID

21518

Title

Combination Lock

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    The combination lock of this problem, as shown in the figure, consists of a circular dial, which can be turned (clockwise or counterclockwise) and is embedded into the "fixed" part of the lock. The dial has N evenly spaced "ticks". The ticks are numbered from 0 to N-1, increasing in the clockwise direction. The fixed part of the lock has a "mark" which always "points to" a particular tick on the dial. Of course, the mark points to different ticks as the dial is turned. (In the figure, N = 40 and the mark points to tick 14.)

    The lock comes with three code numbers T1, T2, T3. These are non-negative integers and each of them is less than N. No two of the three are the same.

    The lock is opened in three stages of operations:

    1. If the mark initially points to tick T1, turn the dial exactly two full revolutions clockwise and stop. Otherwise, turn the dial clockwise exactly two full revolutions, and continue to turn it clockwise until the mark points to tick T1.

    2. Turn the dial one full revolution counterclockwise and continue to turn it counterclockwise until the mark points to tick T2.

    3. Turn the dial clockwise until the mark points to tick T3. The lock should now open.

    Given the numbers N, T1, T2, T3, the goal of this problem is to find the average number of ticks the dial must be turned in order to open the lock. For any particular N, T1, T2, T3 and a particular initial configuration of the lock, the number of ticks turned is defined to be the sum of the ticks turned in the three stages outlined above.

    输入

    The input file consists of a number of test cases, one test case per line. Each line of the input file contains four integers: N, T1, T2, T3, in this order, separated by blank spaces. The integer N is a multiple of 5, 25 ≤ N ≤ 100. The numbers T1, T2 and T3 satisfy the constraints stated under the description above. The input will be terminated by a line containing only four zeroes, separated by blank spaces.

    输出

    Description

    The combination lock of this problem, as shown in the figure, consists of a circular dial, which can be turned (clockwise or counterclockwise) and is embedded into the "fixed" part of the lock. The dial has N evenly spaced "ticks". The ticks are numbered from 0 to N-1, increasing in the clockwise direction. The fixed part of the lock has a "mark" which always "points to" a particular tick on the dial. Of course, the mark points to different ticks as the dial is turned. (In the figure, N = 40 and the mark points to tick 14.)

    The lock comes with three code numbers T1, T2, T3. These are non-negative integers and each of them is less than N. No two of the three are the same.

    The lock is opened in three stages of operations:

    1. If the mark initially points to tick T1, turn the dial exactly two full revolutions clockwise and stop. Otherwise, turn the dial clockwise exactly two full revolutions, and continue to turn it clockwise until the mark points to tick T1.

    2. Turn the dial one full revolution counterclockwise and continue to turn it counterclockwise until the mark points to tick T2.

    3. Turn the dial clockwise until the mark points to tick T3. The lock should now open.

    Given the numbers N, T1, T2, T3, the goal of this problem is to find the average number of ticks the dial must be turned in order to open the lock. For any particular N, T1, T2, T3 and a particular initial configuration of the lock, the number of ticks turned is defined to be the sum of the ticks turned in the three stages outlined above.

    Input

    The input file consists of a number of test cases, one test case per line. Each line of the input file contains four integers: N, T1, T2, T3, in this order, separated by blank spaces. The integer N is a multiple of 5, 25 ≤ N ≤ 100. The numbers T1, T2 and T3 satisfy the constraints stated under the description above. The input will be terminated by a line containing only four zeroes, separated by blank spaces.

    Output

    For each test case, print the average number of ticks (rounded to three decimal places) the dial must be turned in order to open the lock. Assume that each of the N possible initial configurations of the lock is equally likely.

    Sample Input

    80 20 40 50
    80 10 79 12
    0 0 0 0

    Sample Output

    369.500
    415.500

    Source

    样例输入

    80 20 40 50
    80 10 79 12
    0 0 0 0

    样例输出

    369.500
    415.500

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部