Uva 10550 Combination Lock

Sample Input
0 30 0 30
5 35 5 35
0 20 0 20
7 27 7 27
0 10 0 10
9 19 9 19
0 0 0 0
Sample Output
1350
1350
1620
1620
1890
1890

===========================================================================================================

super simple等级

  常量声明  R : 一圈有多少个刻度(这里为40)

  首先我总结了 从刻度A到刻度B顺时针转动的规律 :

  如果A >= B 那么直接取他们的差就是他们相差的刻度, 如果A<B 就是A-B+R 才是他们相差的刻度;

  那么逆时针呢?

  很简单,把从A到B 逆时针转动 转换成  从B到A顺时针 ,那么就只要考虑顺时针这一种情况了

#include<stdio.h>
#define R 40

int degree( int a ,int b){
    if( a> b) return (a-b)*9;
    else return (a-b+R)*9;
}
int main(){
    int a, b ,c,d ,re = 1080;
    while( scanf("%d%d%d%d",&a,&b,&c,&d) && !(!a && !b && !c && !d)){
        re = 1080;
        re+= degree(a,b);
        re+= degree(c,b);
        re+= degree(c,d);
        printf("%d
",re);
    } 
    return 0;
}

  有更好的想法? 欢迎邮件 ethanxlj@foxmail.com

原文地址:https://www.cnblogs.com/foxblogs/p/7708910.html