HDU ACM 1006 Tick and tick

Source: Internet
Author: User

Test instructions: Three hands of a clock keep turning, they get tired of it, and when they are closer to each other, they will be happy to ask how much time they happy in a day as a percentage of the total time.

Analysis: Just find a minute, they happy the time, and then the clock every 12 hours equivalent to 43,200 seconds recovery. So the total time is 43,200 seconds, only ask for in this 43200 happy time, can calculate the percentage. Enumerate 12*60 minutes, see how many seconds in a minute is the time of the happy, and solve three inequalities within a minute to get the interval.

Steps:

1. List the relationship between the pointer (h:m:s) and the degree (RH:RM:RS):
Second hand: rs=6*s;           Minute hand: RM=6*M+S/10; Hour rh=30*h+0.5*m+s/120;
2, the angle between the needles are as follows:
Minute and second hand: rm-rs=6*m+ (0.1-6) *s;       Hour and second hand: rh-rs=30*h+0.5*m+ (1/120)-6) *s; Hour and Minute Hands: rh-rm=30*h+ (0.5-6) *m+ ((1/120) -0.1) *s;
3, the degree between the pointer between D to 360-d, that is, to solve the inequalities of three |ax+b| type: (S is the only unknown), when the Yu Jie equation: d<=a*x+b<=360-d (note positive and negative), and [0,60] take the intersection (also that is 0-60 seconds).
4, to find out any minute of the second hand value range, and then every minute to ask for, accumulate to get the final result.

#include <iostream>using namespace Std;struct range//interval {double l,r;}; Double D; Range Sovle (double a,double b)//solution equation d<=a*x+b<=360-d, and [0,60] take intersection {Range ans;if (a>0) {ans.l= (d-b)/a;ans.r= (360 -d-b)/A;} Else{ans.r= (d-b)/a;ans.l= (360-d-b)/A;}   if (ans.l<0) ans.l=0; Find out if (ans.r>60) ans.r=60;if (ANS.L&GT;=ANS.R) ans.l=ans.r=0; Empty set return ans;} Range Intersect (const range& a,const range& B)//Fetch intersection {Range ANS;ANS.L=A.L&GT;B.L?A.L:B.L;ANS.R=A.R&LT;B.R?A.R: B.r;if (ANS.L&GT;=ANS.R) ans.l=ans.r=0; Empty set return ans;} Double Process (int h,int m)//calculates the number of seconds that M ticks meet test instructions in H, {double A, B;      Range s[3][2]; range, including positive and negative.  Range rans;double Ans;int i,j,k;a=1.0/120-0.1; Solution Equation D<=|hh-mm|<=360-d,hh=30*h+m/2+s/120,mm=6*m+s/10;b=30*h+m/2.0-6*m;s[0][0]=sovle (A, b); S[0][1]=sovle (-  A,-b); a=1.0/120-6.0; Solution Equation D<=|hh-ss|<=360-d,hh=30*h+m/2+s/120,ss=6*s;b=30*h+m/2.0;s[1][0]=sovle (A, b); S[1][1]=sovle (-a,-b); a=  0.1-6; Solution Equation D<=|mm-ss|<=360-d,mm=6*m+s/10,ss=6*s;b=6*m;s[2][0]=sovle (A, b); S[2][1]=sovle (-A,-b); ans=0;for (i=0;i<2;i++)//Six intervals, select three for the intersection for (j=0;j<2;j++)//absolute value of the two intervals to be and three different expression range to be handed, so there are six cases for (k=0 ; k<2;k++) {Rans=intersect (Intersect (S[0][i],s[1][j]), s[2][k]); ANS+=RANS.R-RANS.L;} return ans;} int main () {double ans,h,m;while (scanf ("%lf", &d) ==1 && d!=-1) {ans=0;for (h=0;h<12;h++)//Hourly for (m=0;m  <60;m++)//ans+=process per minute (h,m);p rintf ("%.3lf\n", ans*100.0/(60*60*12)); Percent} return 0;}


HDU ACM 1006 Tick and tick

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.