HDU 5387 Clock(简单模拟)——2015 Multi-University Training Contest 8

227 篇文章 0 订阅
39 篇文章 0 订阅

传送门

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1178    Accepted Submission(s): 671


Problem 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 (1T104) test cases
for each case,one line include the time

0hh<24 ,
0mm<60 , 0ss<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

Hint
每行输出数据末尾均应带有空格
 

Author
SXYZ
 

Source

题目大意:

给你一个 24 小时的时刻,时:分:秒,让你求时针与分针、时针和秒针以及分针和秒针的角度(取 180 )。

解题思路:

这个题目就是一个模拟,我们将其全部换算为一个单位上也就是 时针一秒走多少角度,分针一秒走多少角度,把这个求出来之后:

秒针: 1 秒走 6°

分针: 1 秒走 110°

时针: 1 秒走 1120°

因为带有分数, 所以我们将其分子分母同乘以 120 得到的是整数,然后进行一系列的操作就行了,还有就是 12hh 的将其化为 0  11

之间的数就 OK ,最后在除以 120ans 的最大公约数就行了。

My Code

/**
2016 - 08 - 31 下午
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
    LL res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
int Scan_Int()///输入外挂
{
    int res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
void Out(LL a)///输出外挂
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}
inline int GCD(int a, int b)
{
    if(b == 0)
        return a;
    return GCD(b, a%b);
}
int main()
{
    int T, h, m, s, all = 360*120;
    cin>>T;
    while(T--)
    {
        scanf("%d:%d:%d",&h,&m,&s);
        if(h >= 12)
            h -= 12;
        h = h*3600 + m*60 + s;
        m = m*60 + s;
        s = s*6;
        m = m*12;
        s = s*120;
        int hm = abs(h-m);
        int hs = abs(h-s);
        int ms = abs(m-s);
        hm = min(all-hm, hm);
        hs = min(all-hs, hs);
        ms = min(all-ms, ms);
        int hm1 = GCD(hm, 120);
        int hs1 = GCD(hs, 120);
        int ms1 = GCD(ms, 120);
        if(hm1 != 120)
            printf("%d/%d ",hm/hm1,120/hm1);
        else
            printf("%d ",hm/hm1);
        if(hs1 != 120)
            printf("%d/%d ",hs/hs1,120/hs1);
        else
            printf("%d ",hs/hs1);
        if(ms1 != 120)
            printf("%d/%d \n",ms/ms1,120/ms1);
        else
            printf("%d \n",ms/ms1);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值