• hdu5387(2015多校8)--Clock(模拟)


    题目链接:点击打开链接

    题目大意:给出一个时间,问在钟表上这个时间的时候。时针和分针的角度,时针和秒针的角度。分针和秒针的角度。假设不是整数以分数的形式输出。

    假设依照最小的格来算,那么:

    1s对于秒针来说走1格,分针走12/720格。时针走1/720格。

    1m对于分针来说走一个,时针走60/720格。

    1h对于时针来说走5格。

    计算给出的时间中时针,分针。秒针走的格数,相减得到差,每一格代表6度。

    注意

    1、整数的情况,当中有0,180和其他情况

    2、取余

    3、输出的角度0 <= j <= 180,所以要注意选小的角。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std ;
    struct time{
        int x , y ;
    }h , m , s , temp ;
    int gcd(int a,int b) {
        return b == 0 ? a : gcd(b,a%b) ;
    }
    void f(time temp) {
        if( temp.x%temp.y == 0 ) {
            temp.x /= temp.y ;
            temp.x %= 360 ;
            if( temp.x%360 == 0 )
                printf("0 ") ;
            else if( temp.x%180 == 0 )
                printf("180 ") ;
            else
                printf("%d ", min(temp.x,360-temp.x) ) ;
        }
        else{
            temp.x %= (360*120) ;
            temp.x = min(temp.x,360*120-temp.x) ;
            int k = gcd(temp.x,temp.y) ;
            printf("%d/%d ", temp.x/k, temp.y/k) ;
        }
    }
    int main() {
        int t , a , b , c ;
        scanf("%d", &t) ;
        while( t-- ) {
            scanf("%d:%d:%d", &a, &b, &c) ;
            h.x = 3600*a + 60*b + c ;
            m.x = 720*b + 12*c ;
            s.x = 720*c ;
            temp.x = abs(h.x-m.x) ;
            temp.y = 120 ;
            f(temp) ;
            temp.x = abs(h.x-s.x) ;
            f(temp) ;
            temp.x = abs(m.x-s.x) ;
            f(temp) ;
            printf("
    ") ;
        }
        return 0 ;
    }
    


  • 相关阅读:
    教你彻底弄懂JS中this的指向
    js-原型,原型链
    Firefox SyntaxError: invalid regexp group ChunkLoadError: Loading chunk task-show-task-show-module failed.
    什么是标签语义化?标签语义化有什么意义?
    什么是事件委托?jquery和js怎么去实现?
    express框架
    es6
    node搭建服务器
    node内容
    ajax面试题
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7227658.html
Copyright © 2020-2023  润新知