Title Address: HDU 5387
Test instructions: Give you a time format of HH:MM:SS, ask the hour and minute hand, the hour and the second hand, the minute between the hand and the second hand, the angle between the number of degrees, if the clip angle is not an integer, then output A/b the simplest fraction form.
Idea: Every second, the minute hand walk is 0.1°, the hour hand walks (1/120) °, every minute, the hour hand walks 0.5°. So for the angle of the hour hand in total walking h*30+m*0.5+s/120, for the minute hand angle of the total walk away from the m*6+s*0.1, for the second hand, a total of walking s*6. Because multiplication compares division, time complexity is more precise, so we take the angle of walking 120, all are integers, and finally 120 can be removed. Oh Oh ~ Note the case where the angle difference is greater than 180 °.
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef__int64 LL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7;voidgcdintAintb) {intAa=a;intBb=b; while(b!=0) {intR=b; B=a%b; c=0; }printf("%d/%d", aa/a,bb/a);}intMain () {intT,h,m,s,a,b,c;scanf("%d", &t); while(t--) {scanf("%d:%d:%d", &h,&m,&s); h%= A;if(h== -) h=0;Else if(h> A) h=h- A; h=h*3600+m* -+s; m=m*720+s* A; s*=720; A=ABS(H-M); b=ABS(h-s); C=ABS(m-s);if(a>21600) a=43200-A;if(b>21600) b=43200-B;if(c>21600) c=43200C;if(a% -) GCD (A, -);Else printf("%d", A/ -);if(b% -) gcd (b, -);Else printf("%d", b/ -);if(c% -) gcd (c, -);Else printf("%d", c/ -);printf("\ n"); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5387 (2015 + school 8)-clock (analog)