CodeForces

来源:互联网 发布:申请多个淘宝账号 编辑:程序博客网 时间:2024/06/15 13:52
C. Tram
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 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 x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.

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

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 t2 seconds). He can also stand at some point for some time.

Input

The first line contains three integers sx1 and x2 (2 ≤ s ≤ 10000 ≤ x1, x2 ≤ sx1 ≠ x2) — 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 t1 and t2 (1 ≤ t1, t2 ≤ 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 - 1d is either 1 or ) — the position of the tram in the moment Igor came to the point x1 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.

Output

Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.

Examples
input
4 2 43 41 1
output
8
input
5 4 01 23 1
output
7
Note

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 x2 and get to the point 1 in 6 seconds (because he has to pass 3meters, 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 1meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.



好多人输给了题意,输入这么多数字,还有看不懂的英语。

题目说隧道长为s,人在x1处,想去x2处,人每t1秒走一米,电车每t2秒走一米,电车在p处,d代表电车的朝向,只有1和-1,人可以随便走,电车只能朝单一方向,切且到隧道尽头原速折回,人可以乘车,可以不行,且只能在整数处乘车,问人从x1到x2的最小时间。


人的用时是固定的,而电车就要考虑多种情况,且人若是坐车,用时也是车到目的地的时间,所以重点在于求车的用时,这与车的方向跟位置有关。每种情况画图便可得知。


#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int s,x1,x2,t1,t2,step,flag; //step代表车的位置,flag代表车的方向 
int sum,ave,ave1;
while(scanf("%d%d%d",&s,&x1,&x2)!=EOF)
{
scanf("%d%d%d%d",&t1,&t2,&step,&flag);
if(flag==1)   //正向行驶 
{
ave=fabs(x2-x1)*t2;  //人的用时 
if(step<=x1&&x1<x2)  //车更靠近起点,且x1比x2近 
                ave1=(x2-step)*t1;  
            else if(x1<x2)       //车比距离原点近的x1点远,人一开始追不上车,所以要等车再回来 
                ave1=(s-step+s+x2)*t1;  
            else if(x2<x1)       //逆向走,车要走到终点掉头 
                ave1=(s-step+s-x2)*t1; 
}
if(flag==-1)     //逆向行驶 
{
ave=fabs(x2-x1)*t2;  //人的用时 
if(step>=x1&&x2<x1)  //车远离起点,且目的地需要逆向走 
                ave1=(step-x2)*t1;  
            else if(x2<x1)       //车比x2点近,且逆向,但人追不上车,所以要再折回 
                ave1=(step+s+s-x2)*t1;  
            else if(x1<x2)      //逆向 
                ave1=(step+x2)*t1; 
}
printf("%d\n",ave>ave1?ave1:ave);
}

return 0;

0 0