zoukankan      html  css  js  c++  java
  • 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 ;
    }
    


  • 相关阅读:
    C#之反射
    关系数据库中的函数依赖
    关系型数据库中关系的完整性
    sql的自连接
    sql中的union和union all查询
    c# 泛型之约束
    c#之泛型
    PTA 乙级 1009 说反话(20分) C/C++、Python
    PTA 乙级 1008 数组元素循环右移问题 (20分) C、C++
    PTA 乙级 1007 素数对猜想 (20分) C/C++
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7227658.html
Copyright © 2011-2022 走看看