Slow periods:
07:00 - 10:00
15:00 - 19:00
Input: (sample):
05:00
|
This is a Math problem.
Speed graph over time:
|
The distance travelled per min outside congestion = 1 In T min, distance travelled = T |
The distance travelled per min inside congestion = 0.5 In T min, distance travelled = 0.5×T |
The question ask to find Tend where:
Area from Tstart to Tend = 120 min (= 2 hrs)
|
You can technically solve this problem analytically But this is Computer Science... So we do it algorithmically |
double totCommTime = 2*60; // 2 hrs
int startHr, startMin;
scanf("%d:%d", &startHr, &startMin);
int now = startHr*60 + startMin; // Current time in #minutes
while ( totCommTime > 0.0 )
{
Simulate commute travel for 1 min
now++;
}
(Print now in HH:MM format for answer)
|
double totCommTime = 2*60; // 2 hrs
int startHr, startMin;
scanf("%d:%d", &startHr, &startMin);
int now = startHr*60 + startMin; // Current time in #minutes
while ( totCommTime > 0.0 )
{
if ( now is OUTSIDE the slow periods )
totCommTime -= 1.0; // Each passing min cuts commute time by 1 min
else
totCommTime -= 0.5; // We make 1/2 the progress in slow periods...
now++;
}
(Print now in HH:MM format for answer)
|
DEMO: CCC/2016/Progs/j4.cc
int totCommTime = 2*2*60; // We use 0.5 min as time unit !
int startHr, startMin;
scanf("%d:%d", &startHr, &startMin);
int now = startHr*60 + startMin; // Current time in #minutes
while ( totCommTime > 0 )
{
if ( now is OUTSIDE the slow periods )
totCommTime -= 2; // 2 half min = 1 min
else
totCommTime -= 1; // 1 half min...
now++;
}
(Print now in HH:MM format for answer)
|
DEMO: CCC/2016/Progs/j4-int.cc