Topic
A. Elevator or stairs?
Description
Masha to go from the X-storey to the Y-floor to find Egor, you can choose to climb stairs or take a helicopter elevator. It is known that climbing stairs each layer needs time T1; The helicopter elevator each floor needs time T2, the helicopter elevator opens or closes once needs the time T3, the current helicopter elevator in the z floor, the helicopter elevator door is in the closed state. If the total time to climb stairs is strictly less than the helicopter elevator, then choose to climb the stairs and output yes, otherwise choose to take the helicopter elevator and output No.
Data range: 1<=x,y,z,t1,t2,t3<=1000
Ideas
Total length of Stair climb: t1*abs (x-y)
Total duration of helicopter lift: t2* (ABS (X-Z) +abs (x-y)) +t3*3
Note: The helicopter elevator door needs to switch three times altogether
"My Implementation"
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 7 using namespacestd;8 9InlineintMy_abs (intx)Ten { One returnX <0? -x:x; A } - - intMain () the { - intx, y, z, t1, t2, T3; - intA, B; -scanf"%d%d%d%d%d%d", &x, &y, &z, &t1, &t2, &T3); +A = T1 * My_abs (yx); -b = T2 * (My_abs (x-z) + my_abs (x-y)) +3*T3; + //cout << a << ' << b <<endl; A if(b <=a) atprintf"YES"); - Else -printf"NO"); - return 0; -}
View Code
"Evaluation Results"
Exercises Mail.ru Cup 2018 Round 1-a. Elevator or stairs?