模拟 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 * File Name     :H.cpp
 9  ************************************************/
10
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 1e5 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36 char str[11];
37
38 int GCD(int a, int b)   {
39     return (b == 0) ? a : GCD (b, a % b);
40 }
41
42 int main(void)    {     //HDOJ 5387 Clock
43     int T;  scanf ("%d", &T);
44     while (T--) {
45         int h = 0, m = 0, s = 0;
46         int hh[2], mm[2], ss[2];
47         scanf ("%s", str + 1);
48         h = (h + (str[1] - ‘0‘)) * 10 + str[2] - ‘0‘;
49         m = (m + (str[4] - ‘0‘)) * 10 + str[5] - ‘0‘;
50         s = (s + (str[7] - ‘0‘)) * 10 + str[8] - ‘0‘;
51
52         if (h >= 12)    h -= 12;        //WA点
53
54         hh[0] = 3600 * h + 60 * m + s;      //角度
55         mm[0] = 720 * m + 12 * s;
56         ss[0] = 720 * s;
57
58         int tmp = hh[0];                    //计算角度差,要在0~180度内
59         hh[0] = abs (hh[0] - mm[0]);
60         hh[0] = min (hh[0], 360*120 - hh[0]);
61         int tmp2 = mm[0];
62         mm[0] = abs (tmp - ss[0]);
63         mm[0] = min (mm[0], 360*120 - mm[0]);
64         ss[0] = abs (tmp2 - ss[0]);
65         ss[0] = min (ss[0], 360*120 - ss[0]);
66
67         hh[1] = GCD (120, hh[0]);           //求GCD,化简
68         mm[1] = GCD (120, mm[0]);
69         ss[1] = GCD (120, ss[0]);
70
71         if (hh[0] % 120 == 0) {             //输出
72             printf ("%d ", hh[0] / 120);
73         }
74         else   {
75             printf ("%d/%d ", hh[0] / hh[1], 120 / hh[1]);
76         }
77         if (mm[0] % 120 == 0) {
78             printf ("%d ", mm[0] / 120);
79         }
80         else   {
81             printf ("%d/%d ", mm[0] / mm[1], 120 / mm[1]);
82         }
83         if (ss[0] % 120 == 0) {
84             printf ("%d \n", ss[0] / 120);
85         }
86         else   {
87             printf ("%d/%d \n", ss[0] / ss[1], 120 / ss[1]);
88         }
89     }
90
91     return 0;
92 }
时间: 2024-10-22 20:39:47

模拟 HDOJ 5387 Clock的相关文章

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 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'&&

hdoj 5387(Clock)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5387 比较水的一道题目,也是自己单翘的第一道题目吧,题意就是找到给定时间时钟三个指针之间的夹角, 需要注意的问题分数的表示方法,辗转相除求最大公因子,同时除去, 此外还应注意夹角为锐角. 1 #include<stdio.h> 2 #include<cmath> 3 #include<algorithm> 4 using namespace std; 5 int gcd(i

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

模拟 HDOJ 4552 Running Rabbits

题目传送门 1 /* 2 模拟:看懂题意,主要是碰壁后的转向,笔误2次 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <vector> 8 using namespace std; 9 10 const int MAXN = 1e3 + 10; 11 const int INF = 0x3f3f3f3f; 12 struct Rabbit 13

模拟 HDOJ 5095 Linearization of the kernel functions in SVM

题目传送门 1 /* 2 题意:表达式转换 3 模拟:题目不难,也好理解题意,就是有坑!具体的看测试样例... 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #i

模拟 HDOJ 5099 Comparison of Android versions

题目传送门 1 /* 2 题意:比较型号的大小 3 模拟:坑点在长度可能为5,此时设为'A' 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #include &l

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