您的位置:首页 > 其它

HDU 5387 Clock(模拟)——(多校练习8)

2015-08-13 15:16 344 查看


Clock

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

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每行输出数据末尾均应带有空格

 
/*********************************************************************/

题意:给你一个格式为hh:mm:ss的时间,问改时间时针与分针、时针与秒针、分针与秒针之间夹角的度数是多少,若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质。

解题思路:该题的思路很简单,只需先将时针、分针、秒针代表的时间转换成距离0刻度的角度,然后再求两者之间夹角的度数就会方便许多,需要注意,每秒钟,秒针对分针的贡献是0.1°,秒针对时针的贡献是(1/120)°;每分钟,分针对时针的贡献是0.5°。为了使得计算角度时均为整数,本人特地将角度放大了120倍,最后反正是要化成最简分数形式的,故再除以120即可。

其他细节之处会在代码中作出解释。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 1005;
const int inf = 1000000000;
const int mod = 1000000007;
void gcd(int a,int b)//利用辗转相除法求最大公约数,使得分数最简
{
int m=a,n=b;
while(a!=b)
if(a>b)
a=a-b;
else
b=b-a;
printf("%d/%d ",m/a,n/a);
}
int main()
{
int t,h,m,s,a,b,c;
scanf("%d",&t);
while(t--)
{
scanf("%d:%d:%d",&h,&m,&s);
h%=12;//时钟一圈12小时,故24小时制的时间要转换成12小时制
h=h*3600+m*60+s;//时针、分针、秒针的角度均放大120倍,使计算过程中不会出现小数
m=m*720+s*12;
s*=720;
//printf("%d %d %d*\n",h,m,s);
a=abs(h-m);//计算时针与分针之间的夹角
b=abs(h-s);//计算时针与秒针之间的夹角
c=abs(m-s);//计算分针与秒针之间的夹角
if(a>21600)//当夹角超过180°时,通过360°减去当前夹角使夹角小于180°
a=43200-a;
if(b>21600)
b=43200-b;
if(c>21600)
c=43200-c;
//printf("%d %d %d#\n",a,b,c);
if(a%120)
gcd(a,120);
else
printf("%d ",a/120);
if(b%120)
gcd(b,120);
else
printf("%d ",b/120);
if(c%120)
gcd(c,120);
else
printf("%d ",c/120);
printf("\n");
}
return 0;
}

菜鸟成长记
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: