[題解]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

【評測結果】

相關文章
相關標籤/搜索