编程介的小学生 2020-02-16 12:11 采纳率: 20.5%
浏览 152

Combination Lock 组合锁的问题

Problem Description

A combination lock 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.

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. 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.

You must find the maximum possible number of ticks the dial must be turned in order to open the lock. The number of ticks turned is defined to be the sum of the ticks turned in the three stages outlined above, and is always positive regardless of direction.

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 with N = T1 = T2 = T3 = 0 .

Output
For each test case, print the maximum possible number of ticks the dial must be turned in order to open the lock. Print each on its own line.

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

Sample Output
409
455

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器