Bigital
TCO07 Qual 1 · 2007-03-07 · by dgoodman
Problem Statement
For example, 03:22:59 requires 8 lights to be on and looks like this:
0 0 0 0 0 1
0 0 0 0 1 0
0 1 1 1 0 0
0 1 0 0 1 1
Given tStart and tEnd, return the total number of kilowatt
hours used by the clock in displaying all the times from tStart to tEnd,
inclusive. The start and end time are less than 12 hours apart.
Notes
- A kilowatt hour is the energy used when using 1000 watts for an hour.
- A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
- tStart and tEnd will each contain exactly 8 characters.
- tStart and tEnd will each be in the form hh:mm:ss, where hh is between 01 and 12, inclusive, mm is between 00 and 59, inclusive, and ss is between 00 and 59, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
"12:00:00" "12:00:00" Returns: 5.555555555555555E-7
Two bulbs are on for just one second. This require 2 watt seconds which (60 seconds per minute, 60 minutes per hour, 1000 watts per kilowatt) is .000000555555555 kilowatt hours of energy.
"12:59:59" "01:00:00" Returns: 3.0555555555555556E-6
Here the clock is running for 2 seconds, with lots of lights on for the first second and only 1 on for the second second.
"12:01:00" "12:00:00" Returns: 0.08392277777777778
This is almost the full 12 hours.
"07:00:00" "05:00:20" Returns: 0.06935638888888888
"01:01:59" "01:01:58" Returns: 0.084
Submissions are judged against all 52 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Bigital with a public method double energy(string tStart, string tEnd) · 52 test cases · 2 s / 256 MB per case