CF746C.Tram

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per _t_1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.

Igor is at the point _x_1. He should reach the point _x_2. Igor passes 1 meter per _t_2 seconds.

Your task is to determine the minimum time Igor needs to get from the point _x_1 to the point _x_2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point _x_1.

Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per _t_2 seconds). He can also stand at some point for some time.

伯兰的有轨电车沿一条直线从点 00 行驶至点 ss,再原路返回,往返过程中均以每 t1t_1 秒行驶 1 米的速度做匀速直线运动。这意味着电车始终处于匀速直线运动状态,并在端点 x=0x = 0 和 x=sx = s 处瞬间掉头。

伊戈尔位于点 x1x_1,他需要到达点 x2x_2。伊戈尔步行速度为每 t2t_2 秒行走 1 米。

你的任务是:在已知伊戈尔抵达点 x1x_1 的时刻电车所处位置及其行驶方向的前提下,求出伊戈尔从点 x1x_1 到达点 x2x_2 所需的最少时间。

伊戈尔可在任意时刻(只要其位置与电车位置重合)无限次地登上电车;上下车地点不一定是整数坐标点。假设所有上下车过程均瞬时完成。伊戈尔可沿该直线任意移动(但速度不能超过每 t2t_2 秒 1 米),也可在某点停留任意时长。

输入格式

The first line contains three integers s, _x_1 and _x_2 (2 ≤ s ≤ 1000, 0 ≤ _x_1, _x_2 ≤ s, _x_1 ≠ _x_2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.

The second line contains two integers _t_1 and _t_2 (1 ≤ _t_1, _t_2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.

The third line contains two integers p and d (1 ≤ p ≤ s - 1, d is either 1 or ) — the position of the tram in the moment Igor came to the point _x_1 and the direction of the tram at this moment. If , the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.

第一行包含三个整数 ss、x1x_1 和 x2x_2(2 ≤ s ≤ 10002 \leq s \leq 1000,0 ≤ x1, x2 ≤ s0 \leq x_1, x_2 \leq s,且 x1 ≠ x2x_1 \neq x_2)——分别表示有轨电车所能到达的最大坐标值、Igor 当前所在位置的坐标,以及 Igor 需要到达的目标位置的坐标。

第二行包含两个整数 t1t_1 和 t2t_2(1 ≤ t1, t2 ≤ 10001 \leq t_1, t_2 \leq 1000)——分别表示有轨电车行驶 1 米所需的时间(单位:秒)以及 Igor 行走 1 米所需的时间(单位:秒)。

第三行包含两个整数 pp 和 dd(1 ≤ p ≤ s − 11 \leq p \leq s - 1,dd 的取值为 11 或 )——分别表示 Igor 到达点 x1x_1 时刻有轨电车所处的位置,以及此时有轨电车的行驶方向。若 ,则有轨电车正从坐标 ss 向坐标 00 方向行驶;若 d = 1d = 1,则有轨电车正从坐标 00 向坐标 ss 方向行驶。

输出格式

Print the minimum time in seconds which Igor needs to get from the point _x_1 to the point _x_2.

输出 Igor 从点 x1x_1 到点 x2x_2 所需的最少时间(单位:秒)。

输入输出样例

  • 输入#1

    4 2 4
    3 4
    1 1

    输出#1

    8
  • 输入#2

    5 4 0
    1 2
    3 1

    输出#2

    7

说明/提示

In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.

In the second example Igor can, for example, go towards the point _x_2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point _x_2 in 7 seconds in total.

在第一个例子中,对伊戈尔而言,步行前往比等待电车更划算。因此,他需要走完 2 米,总共耗时 8 秒(因为他每 4 秒走 1 米)。

在第二个例子中,伊戈尔可以例如朝点 x2x_2 方向行走,并在 6 秒内到达点 1(因为他需要走 3 米,而他每 2 秒走 1 米)。此时电车恰好也到达点 1,因此伊戈尔可进入电车,并用 1 秒走完 1 米。于是,伊戈尔总共用时 7 秒即可抵达点 x2x_2。

输入解题思路,AI测评打分。不知道怎么写?

首页