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'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
    return c*f;
}
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int main(){
  int t,h,m,s;
   t=read();
   while(t--){
       scanf("%d:%d:%d",&h,&m,&s);
       h%=12;
       m%=60;
       s%=60;

       int ss=s*720;    //秒针走过的角度
       int mm=720*m+12*s;  //分针走过的角度
       int hh=3600*h+60*m+s;  //时针走过的角度

      //计算角度之差
       int hm=abs(hh-mm);
       int hs=abs(hh-ss);
       int ms=abs(mm-ss);
      //判断
       hm=min(hm,120*360-hm);
       hs=min(hs,120*360-hs);
       ms=min(ms,120*360-ms);
      //取最大公约数
       int ghm=gcd(hm,120);
       int ghs=gcd(hs,120);
       int gms=gcd(ms,120);

       if(ghm==120) cout<<hm/120;
       else cout<<hm/ghm<<"/"<<120/ghm;

       if(ghs==120) cout<<" "<<hs/120<<" ";
       else cout<<" "<<hs/ghs<<"/"<<120/ghs<<" ";

        if(gms==120) cout<<ms/120<<" "<<endl;
       else cout<<ms/gms<<"/"<<120/gms<<" "<<endl;
   } return 0;
}

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

时间: 2024-08-27 21:30:36

HDU 5387 Clock (MUT#8 模拟)的相关文章

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

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.hou

HDU 5386 Cover (MUT #8 模拟暴力)

[题目链接]:click here~~ [题意]: 操作L x y,把当前x,这一列全部置为y 操作H x y,把当前,这一行全部置为y. 现在给你n?n的初始矩阵,以及n?n的目标矩阵 现在给你m种操作(由以上两种操作构成),问怎么排序这m种操作,才能使得,初始矩阵,经由排序后的操作,构成目标矩阵. 输出排序方案. 也就是给出初始矩阵和目标矩阵,存在m中操作,可以分别把每行或者每列都涂成同一种颜色,数据保证有解,因为保证有解,(然而初始矩阵并没有什么卵用...) [思路]: 暴力寻找M次操作,

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 3887树状数组+模拟栈

题目链接 Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1757    Accepted Submission(s): 582 Problem Description You are given a tree, it’s root is p, and the node is numbered fr

hdu 4891 The Great Pan(模拟)

题目链接:hdu 4891 The Great Pan 题目大意:给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn+1), si表示连续的空格数. 2.{}中间,即 | 的个数+1. 解题思路:模拟. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1<<22

HDU 4930 Fighting the Landlords 模拟

_(:зゝ∠)_ 4带2居然不是炸弹,, #include <algorithm> #include <cctype> #include <cassert> #include <cstdio> #include <cstring> #include <climits> #include <vector> #include<iostream> using namespace std; #define N 18 #