关闭

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

标签: 模拟
410人阅读 评论(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;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:446153次
    • 积分:10654
    • 等级:
    • 排名:第1617名
    • 原创:632篇
    • 转载:5篇
    • 译文:0篇
    • 评论:89条
    博客专栏