hdu 5387 clock (时间夹角的计算)

已知时间h:m:s,求三个指针任意两个之间的夹角。


分别求出三个指针相对于12的夹角。

秒针:6*s度

分针:6*(m+s/60)度

时针:30*h+0.5*(m+s/60)


由于结果要用分数的形式表示。因此计算的时候将上面结果乘以120,得到整数。最后再和120约分即可。


#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<vector>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef __int64 LI;
typedef unsigned __int64 uLI;
typedef unsigned int uI;
typedef double db;
#define maxn 100005
#define inf 0x3f3f3f3f
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int main()
{
    int T,h,m,s,i,j,k;
    cin>>T;
    while(T--)
    {
        scanf("%d:%d:%d",&h,&m,&s);
        int a,b=120;
        h%=12;
        int t1=3600*h+60*m+s;
        int t2=12*s+720*m;
        int t3=720*s;
        a=abs(t1-t2);
        if(a>180*120) a=360*120-a;
        if(a==0) printf("0 ");
        else{
            int g=gcd(a,b);
            if(g==120) printf("%d ",a/g);
            else printf("%d/%d ",a/g,b/g);
        }
        a=abs(t1-t3);
        if(a>180*120) a=360*120-a;
        if(a==0) printf("0 ");
        else{
            int g=gcd(a,b);
            if(g==120) printf("%d ",a/g);
            else printf("%d/%d ",a/g,b/g);
        }
        a=abs(t2-t3);
        if(a>180*120) a=360*120-a;
        if(a==0) printf("0 \n");
        else{
            int g=gcd(a,b);
            if(g==120) printf("%d \n",a/g);
            else printf("%d/%d \n",a/g,b/g);
        }
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值