HDU 5387 Clock

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 422    Accepted Submission(s): 294

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(1≤T≤104) test
cases

for 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 

Hint

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

Author

SXYZ

Source

2015 Multi-University Training Contest 8

题意:给你一个时刻,求出时针与分针,分针与秒针,秒针与时针的夹角。

题解:分别求出时针,分针,秒针与12整点的夹角,求的时候把夹角*120,再求两两的夹角除以120.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#define ll int

using namespace std;

ll gcd(ll a,ll b) {
    return b==0?a:gcd(b,a%b);
}

int main() {
    //freopen("test.in","r",stdin);
    int t;
    cin>>t;
    while(t--) {
        int h,m,s;
        scanf("%d:%d:%d",&h,&m,&s);
        if(h>=12)h-=12;
        ///ah=h*30+0.5*m+s/120  120为分母的公倍数
        int ah=h*30*120+m*60+s;///时针与12正点的夹角*120
                               ///放大120倍是她为整数,下面同理
        int am=m*6*120+s*12;
        int as=6*s*120;
        int gd=120;
        int a1,a2,a3;
        ///时-分
        a1=ah>am?ah-am:am-ah;
        a1=a1>180*120?360*120-a1:a1;
        ///分-秒
        a2=am>as?am-as:as-am;
        a2=a2>180*120?360*120-a2:a2;
        ///秒-时
        a3=as>ah?as-ah:ah-as;
        a3=a3>180*120?360*120-a3:a3;
        if(a1%gd==0)
            printf("%d ",a1/gd);
        else
            printf("%d/%d ",a1/gcd(a1,gd),gd/gcd(a1,gd));
        if(a3%gd==0)
            printf("%d ",a3/gd);
        else
            printf("%d/%d ",a3/gcd(a3,gd),gd/gcd(a3,gd));
        if(a2%gd==0)
            printf("%d ",a2/gd);
        else
            printf("%d/%d ",a2/gcd(a2,gd),gd/gcd(a2,gd));
        cout<<endl;
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-25 16:43:23

HDU 5387 Clock的相关文章

HDU 5387 Clock(分数类+模拟)

题意: 给你一个格式为hh:mm:ss的时间,问:该时间时针与分针.时针与秒针.分针与秒针之间夹角的度数是多少. 若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质. 解析: 先计算出总的秒数 S=hh?3600+mm?60+ss 由于秒钟每秒走1°, 所以当前时间,秒钟与12点的度数为 S%360 由于分针每秒走 0.1°, 既然已经计算出总秒数,那么当前时间,分针与12点的度数为 S/10%360 由于时针每秒走(1/120)°.那么当前时间.时针与12点的度数为 S/120%360

hdu 5387 Clock (模拟)

#include<iostream> #include<algorithm> #include<cstring> #include<math.h> #include<stdio.h> #include<map> using namespace std; int gcd(int x,int y) { return y==0?x:gcd(y,x%y); } int main() { int h,m,s; int x,y,z,t; int

HDU 5387 Clock (MUT#8 模拟)

[题目链接]:click here~~ [题目大意]给定一个时间点,求时针和分针夹角,时针和秒针夹角,分针和秒针夹角 模拟题,注意细节 代码: #include<bits/stdc++.h> using namespace std; inline int read(){ int c=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&

HDU 5387(2015多校8)-Clock(模拟)

题目地址:HDU 5387 题意:给你一个格式为hh:mm:ss的时间,问时针与分针.时针与秒针.分针与秒针之间夹角的度数是多少,若夹角度数不是整数,则输出A/B最简分数形式. 思路:每秒钟,分针走是0.1°,时针走(1/120)°:每分钟,时针走0.5°.所以对于时针的角度来说总共走动了h*30+m*0.5+s/120,对于分针的角度来说总共走掉了m*6+s*0.1,对于秒针来说,总共走动了s*6.因为乘法比较除法来说时间复杂度更精确一点,所以我们把走的角度*120,变成全部都是整数,最后再除

模拟 HDOJ 5387 Clock

题目传送门 1 /* 2 模拟:这题没啥好说的,把指针转成角度处理就行了,有两个注意点:结果化简且在0~180内:小时13点以后和1以后是一样的(24小时) 3 模拟题伤不起!计算公式在代码内(格式:hh/120, mm/120, ss/120) 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-13 13:04:31 8 * Fil

【HDU 5387】Clock

题 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\leq T \leq 10^4)$ test cases for each case,one line

hdu 1209 Clock

Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5870    Accepted Submission(s): 1872 Problem Description There is an analog clock with two hands: an hour hand and a minute hand. The two ha

HDOJ 5387 Clock 水+模拟

Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 316    Accepted Submission(s): 215 Problem Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hou

杭电 HDU 1209 Clock

Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5140    Accepted Submission(s): 1589 Problem Description There is an analog clock with two hands: an hour hand and a minute hand. The two h