练习cf1054A. Elevator or Stairs?

题目如下
A. Elevator or Stairs?
time limit per test1 second
memory limit per test256 megabytes
Masha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on the floor 𝑥, Egor on the floor 𝑦 (not on the same floor with Masha).

The house has a staircase and an elevator. If Masha uses the stairs, it takes 𝑡1 seconds for her to walk between adjacent floors (in each direction). The elevator passes between adjacent floors (in each way) in 𝑡2 seconds. The elevator moves with doors closed. The elevator spends 𝑡3 seconds to open or close the doors. We can assume that time is not spent on any action except moving between adjacent floors and waiting for the doors to open or close. If Masha uses the elevator, it immediately goes directly to the desired floor.

Coming out of the apartment on her floor, Masha noticed that the elevator is now on the floor 𝑧 and has closed doors. Now she has to choose whether to use the stairs or use the elevator.

If the time that Masha needs to get to the Egor's floor by the stairs is strictly less than the time it will take her using the elevator, then she will use the stairs, otherwise she will choose the elevator.

Help Mary to understand whether to use the elevator or the stairs.

Input
The only line contains six integers 𝑥, 𝑦, 𝑧, 𝑡1, 𝑡2, 𝑡3 (1≤𝑥,𝑦,𝑧,𝑡1,𝑡2,𝑡3≤1000) — the floor Masha is at, the floor Masha wants to get to, the floor the elevator is located on, the time it takes Masha to pass between two floors by stairs, the time it takes the elevator to pass between two floors and the time it takes for the elevator to close or open the doors.

It is guaranteed that 𝑥≠𝑦.

Output
If the time it will take to use the elevator is not greater than the time it will take to use the stairs, print «YES» (without quotes), otherwise print «NO> (without quotes).

You can print each letter in any case (upper or lower).

题目大意
从a到b楼层,走楼梯还是坐电梯更快?计算两种方式各自需要的时间,如果坐电梯更快或者所需时间相同,那么输出YES选择坐电梯,否则NO

题目分析
根据题意,走楼梯的时间等于楼层之差乘以速度即可;
坐电梯的时间等于,楼层之差乘以电梯速度,还有等电梯的时间,以及等电梯开门关门,走出电梯时的开门,共三次开\关门的时间;

点击查看代码
#include <stdio.h>
#include <cmath>

int main(){
    int x, y, z, t1, t2, t3;
    scanf("%d%d%d%d%d%d",&x,&y, &z, &t1, &t2, &t3);
    int e, s;
    int floor = abs(x - y);
    s = floor * t1;
    e = floor * t2 + abs(x - z) * t2 + t3 * 3;
    if(e <= s)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}
posted @ 2025-07-09 20:20  sirro1uta  阅读(15)  评论(0)    收藏  举报