码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 3104 Combination Lock(数学题)

时间:2014-10-06 23:56:51      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:hdu   数学   

题目链接: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.


bubuko.com,布布扣


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


题意:

转动表盘:

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;
}


HDU 3104 Combination Lock(数学题)

标签:hdu   数学   

原文地址:http://blog.csdn.net/u012860063/article/details/39832005

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!