HDU 5387 (2015 + school 8)-clock (analog)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.