HDU 3104 Combination Lock(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3104

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

Source

2008 ACM-ICPC Southeast USA Regional

题意:

转动表盘:

1、顺时针转动两圈后再转到T1;

2、逆时针转动一圈后再转到T2;

3、顺时针转动到T3;

问最终转了多少格;

PS:

顺时针转动表盘,相当于逆时针转动指针;

代码如下:

#include<cstdio>
int main()
{
    int n;
    int a1,a2,a3;
    int ans;
    while(~scanf("%d%d%d%d",&n,&a1,&a2,&a3))
    {
        if(n==0 && a1==0 && a2==0 && a3==0)
            break;
        ans = 4*n-1;
        if(a2>a1)
        {
            ans+=a2-a1;
        }
        else
        {
            ans+=n+a2-a1;
        }
        if(a3<a2)
        {
            ans+=a2-a3;
        }
        else
            ans+=n+a2-a3;
        printf("%d\n",ans);
    }
    return 0;
}
时间: 2024-10-23 18:01:52

HDU 3104 Combination Lock(数学题)的相关文章

Combination Lock

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Microsoft interviewer is in the room though the door is locked. There is a combination lock on the door. There are N rotators on the lock, each consists o

1.3.4 Combination Lock

Farmer John's cows keep escaping from his farm and causing mischief. To try and prevent them from leaving, he purchases a fancy combination lock to keep his cows from opening the pasture gate. Knowing that his cows are quite clever, Farmer John wants

hihocoder-第六十一周 Combination Lock

题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Microsoft interviewer is in the room though the door is locked. There is a combination lock on the door. There are N rotators on th

Hiho----微软笔试题《Combination Lock》

Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Microsoft interviewer is in the room though the door is locked. There is a combination lock on the door. There are N rotators on the lock

贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

题目传送门 1 /* 2 贪心水题:累加到目标数字的距离,两头找取最小值 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 using namespace std; 9 10 const int MAXN = 1e3 + 10; 11 const int INF = 0x3f3f3f3f; 12 char s[MAXN],

hdu 3123 GCC(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3123 GCC Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 3808    Accepted Submission(s): 1234 Problem Description The GNU Compiler Collection (u

A - Combination Lock

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and

CF #301 A :Combination Lock(简单循环)

A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:

USACO 1.3 Combination Lock

Combination Lock Farmer John's cows keep escaping from his farm and causing mischief. To try and prevent them from leaving, he purchases a fancy combination lock to keep his cows from opening the pasture gate. Knowing that his cows are quite clever,