Clock ZQUOJ 25806 时针角度差问题

Clock

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • Total Submission(s): 6     Accepted Submission(s): 3
Description

Give a time. (hh:mm:ss), you should answer the angle between any two of the minute.hour.second hand

Notice that the answer must be not more 180 and not less than 0

Input

There are T (1 ≤ T ≤ 104) test casesfor each case, one line include the time

0 ≤ hh < 24 ,  0 ≤ mm < 60 ,  0 ≤ ss < 60

Output

for each case, output there real number like A/B. (A and B are coprime). If it's an integer then just print it. describe the angle between hour and minute, hour and second hand, minute and second hand.

Sample Input

4
00:00:00
06:00:00
12:54:55
04:40:00

Sample Output

0 0 0 
180 180 0 
1391/24 1379/24 1/2 
100 140 120

Source
2015 Multi-University Training 8   



思路:计算指针的角度差可以先算出来时针  分针  秒针  现在的总秒数,这个秒数要在指针的范围之内,就是秒针不能超过60,分针不超过60  时针不超过12 .也就说算出该时间的总秒数,然后利用这个总秒数,计算出秒针的走过的角度,因为时针的性质,所以秒针每走一秒就是走6度,那么分针就是6/60  时针就是6/3600,计算出总角度之后,每个角度都要求余360  因为超过360的角度无意义,然后进行分数的减法 得出答案控制在180度以内。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long  type;
struct Frac
{
    type a, b;
    Frac()
    {
        a = 0;
        b = 1;
    }
    Frac(type a)
    {
        this->a = a;
        b = 1;
    }
    Frac(type a, type b)
    {
        this->a = a;
        this->b = b;
        deal();
    }
    void init()
    {
        a = 0;
        b = 1;
    }
    type gcd(type a, type b)
    {
        while (b)
        {
            type tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }
    void deal()
    {
        type d = gcd(a, b);
        a /= d;
        b /= d;
        if (b < 0)
        {
            a = -a;
            b = -b;
        }
    }
    Frac operator + (Frac c)
    {
        Frac ans;
        ans.a = a * c.b + b * c.a;
        ans.b = b * c.b;
        ans.deal();
        return ans;
    }
    Frac operator - (Frac c)
    {
        Frac ans;
        ans.a = a * c.b - b * c.a;
        ans.b = b * c.b;
        ans.deal();
        return ans;
    }
    Frac operator * (Frac c)
    {
        Frac ans;
        ans.a = a * c.a;
        ans.b = b * c.b;
        ans.deal();
        return ans;
    }
    Frac operator / (Frac c)
    {
        Frac ans;
        ans.a = a * c.b;
        ans.b = b * c.a;
        ans.deal();
        return ans;
    }
    Frac operator % (Frac c)
    {
        Frac ans;
        ans.b = b * c.b;
        ans.a = a * c.b % (c.a * b);
        ans.deal();
        return ans;
    }
    void absolute()
    {
        if (a < 0)
            a = -a;
        if (b < 0)
            b = -b;
    }
    void operator += (Frac c)
    {
        *this = *this + c;
    }
    void operator -= (Frac c)
    {
        *this = *this - c;
    }
    void operator *= (Frac c)
    {
        *this = *this * c;
    }
    void operator /= (Frac c)
    {
        *this = *this / c;
    }
    bool operator > (Frac c)
    {
        return a * c.b > b * c.a;
    }
    bool operator == (Frac c)
    {
        return a * c.b == b * c.a;
    }
    bool operator < (Frac c)
    {
        return !(*this < c && *this == c);
    }
    bool operator >= (Frac c)
    {
        return !(*this < c);
    }
    bool operator <= (Frac c)
    {
        return !(*this > c);
    }
    bool operator != (Frac c)
    {
        return !(*this == c);
    }
    bool operator != (type c)
    {
        return *this != Frac(c, 1);
    }
    void operator = (type c)
    {
        this->a = c;
        this->b = 1;
    }
    void put()
    {
        if (a == 0)
            printf("0");
        else
        {
            if (b == 1)
                printf("%lld", a);
            else printf("%lld/%lld", a, b);
        }
    }
};
int t;
type hh, mm, ss;
int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%lld:%lld:%lld", &hh, &mm, &ss);
        type S = hh * 3600 + mm * 60 + ss;
        Frac s = Frac((S * 6) % 360);
        Frac m = Frac(S, 10);
        Frac h = Frac(S, 120);
        m = m % Frac(360);
        h = h % Frac(360);
        Frac a1 = (h - m);
        Frac a2 = (h - s);
        Frac a3 = (m - s);
        a1.absolute();
        a2.absolute();
        a3.absolute();
        if (a1 > Frac(180)) a1 = Frac(360) - a1;
        if (a2 > Frac(180)) a2 = Frac(360) - a2;
        if (a3 > Frac(180)) a3 = Frac(360) - a3;
        a1.put();
        printf(" ");
        a2.put();
        printf(" ");
        a3.put();
        printf(" \n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值