码迷,mamicode.com
首页 > 其他好文 > 详细

hdoj 5387(Clock)

时间:2015-08-15 13:25:37      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: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(int a,int b)
 6 {
 7     int r;
 8     if(a<b) {r=a;a=b;b=r;}
 9     while(b)
10     {
11         r=a%b;
12         a=b;
13         b=r;
14     }
15     return a;
16 }
17 void per( int &a, int &b){
18     int tmp = gcd(a,b);
19     a = a / tmp;
20     b = b / tmp;
21 }
22 void show( int a, int b, int c, int d){
23     if( a / b > 360 )
24         a = a % ( 360 * b);
25     if( c / d > 360 )
26         c = c % ( 360 * d);
27     int son = 6*abs(a*d-b*c);
28     int mot = b*d;
29     son = son %( b*d*360);
30     if( son > b*d*180 )
31         son = b*d*360 - son;
32     per(son,mot);
33     if( mot != 1 )
34         printf("%d/%d ",son,mot);
35     else
36         printf("%d ",son);
37 }
38 int main(){
39 //    freopen("test.out","r",stdin);
40     int T;
41     char in[10];
42     int hh, mm, ss;
43     int total;
44     int total2;
45     int total3;
46     int hour ;
47     int minu ;
48     int sec ;
49     scanf("%d",&T);
50     while(T--){
51         hour = 720;
52         minu = 60;
53         sec = 1;
54         scanf("%s", in);
55         hh = (in[0]-0)*10+(in[1]-0);
56         mm = (in[3]-0)*10+(in[4]-0);
57         ss = (in[6]-0)*10+(in[7]-0);
58         total = ( ss + mm * 60 + hh * 3600 ) % ( 3600 * 12 );
59         total2 = total;
60         total3 = total;
61         per(total,hour);
62         per(total2,minu);
63         per(total3,sec);
64         show(total,hour,total2,minu);
65         show(total,hour,total3,sec);
66         show(total3,sec,total2,minu);
67         printf("\n");
68     }
69 }

 

hdoj 5387(Clock)

标签:

原文地址:http://www.cnblogs.com/blueprintf/p/4732277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!