[题解]Mail.Ru Cup 2018 Round 1 - A. Elevator or Stairs?

【题目】ios

A. Elevator or Stairs?ide

【描述】spa

Masha要从第x层楼去第y层楼找Egor,能够选择爬楼梯或者坐直升电梯。已知爬楼梯每层须要时间t1;坐直升电梯每层须要时间t2,直升电梯开门或者关门一次须要时间t3,当前直升电梯在第z层楼,直升电梯门是在关闭状态的。若是爬楼梯总时间严格小于坐直升电梯,则选择爬楼梯并输出YES,不然选择坐直升电梯并输出NO。3d

数据范围:1<=x,y,z,t1,t2,t3<=1000code

【思路】blog

爬楼梯总时长:t1*abs(x-y)get

坐直升电梯总时长:t2*(abs(x-z)+abs(x-y))+t3*3string

注意:直升电梯门须要开关一共三次it

【个人实现】io

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 
 7 using namespace std;
 8 
 9 inline int My_abs(int x)
10 {
11     return x < 0 ? -x : x;
12 }
13 
14 int main()
15 {
16     int x, y, z, t1, t2, t3;
17     int a, b;
18     scanf("%d%d%d%d%d%d", &x, &y, &z, &t1, &t2, &t3);
19     a = t1 * My_abs(y-x);
20     b = t2 * (My_abs(x-z) + My_abs(x-y)) + 3 * t3;
21     //cout << a << ' ' << b <<endl;
22     if(b <= a)
23         printf("YES");
24     else
25         printf("NO");
26     return 0;
27 }
View Code

【评测结果】

相关文章
相关标签/搜索