zoukankan      html  css  js  c++  java
  • HDU-5387 Clock

    http://acm.hdu.edu.cn/showproblem.php?pid=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,变成全部都是整数,最后再除掉120即可。注意角度差大于180°的情况。要用360度-;

    Clock

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


    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
    每行输出数据末尾均应带有空格
     
    Source
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    using namespace std;
    int gcd(int x,int y)
    {
        if(y%x==0)return x;
        return gcd(y%x,x);
    }
    int abs(int x)
    {
        if(x>0)
          return x;
        else
            return -1*x;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int h,m,s,a,b,c;
            scanf("%d:%d:%d",&h,&m,&s);
            h%=12;
            h=h*3600+m*60+s;
            m=m*720+s*12;
            s=s*720;
            a=abs(h-m);
            b=abs(h-s);
            c=abs(m-s );
            if(a>120*180)
              {
                  a=360*120-a;
              }
              if(b>120*180)
              {
                  b=360*120-b;
              }
              if(c>120*180)
              {
                  c=360*120-c;
              }
             //printf("a=%d,b=%d,c=%d
    ",a,b,c);
              if(a%120==0)
                 printf("%d " ,a/120);
              else
               {
                   int x=gcd(a,120);
                    printf("%d/%d ",a/x,120/x);
               }
               if(b%120==0)
                 printf("%d " ,b/120);
              else
               {
                    int y=gcd(b,120);
                    printf("%d/%d ",b/y,120/y);
                }
             if(c%120==0)
                 printf("%d " ,c/120);
             else
             {
               int z=gcd(c,120);
             printf("%d/%d ",c/z,120/z);
             }
    
            printf("
    ");
    
        }
        return 0;
    }
     
     
  • 相关阅读:
    Liunx基础优化配置
    Linux配置国内的Yum源
    Liunx配置静态IP
    百度前端学院|任务七
    java的远程访问接口的实例
    java套接字实现接口访问
    Mysql的链接超时异常CommunicationsException
    mysql查看和设置timeout 和批量杀死链接进程
    springmvc接受表单多条数据的值
    jquery获取点击标签内的子标签内容和值实例
  • 原文地址:https://www.cnblogs.com/cancangood/p/4729942.html
Copyright © 2011-2022 走看看