我是靠谱客的博主 含糊手链,最近开发中收集的这篇文章主要介绍CodeForces 746C Tram,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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 4
3 4
1 1
output
8
input
5 4 0
1 2
3 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,如果步行走1米需要t2分钟,现在有一辆车,走一米需要t1分钟,位置为P,方向为d (d为1表示正向,-1表示反向走)如果车和人相遇,人可以坐上车,问人从x1到x2做少需要的时间。

思路:模拟这个过程即可。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int s,x1,x2,t1,t2,p,d,i,j;
while(scanf("%d%d%d",&s,&x1,&x2)!=EOF)
{
scanf("%d%d",&t1,&t2);
scanf("%d%d",&p,&d);
int dir=1;
if(x2<x1)
dir=-1;
if(dir==1)
{
int igort=(x2-x1)*t2;
if(d==1)
{
int tram;
if(p<=x1)
{
tram=(x2-p)*t1;
}
else if(p>x1)
{
tram=((s-p)+s+x2)*t1;
}
if(igort<=tram)
{
printf("%dn",igort);
}
else
{
printf("%dn",tram);
}
}
else if(d==-1)
{
int tram=(p+x2)*t1;
if(igort<=tram)
{
printf("%dn",igort);
}
else
{
printf("%dn",tram);
}
}
}
if(dir==-1)
{
int igort=(x1-x2)*t2;
int tram;
if(d==1)
{
tram=(s-p+s-x2)*t1;
if(igort<=tram)
{
printf("%dn",igort);
}
else
{
printf("%dn",tram);
}
}
else
{
if(p<x1)
{
tram=(p+s+(s-x2))*t1;
}
else
{
tram=(p-x2)*t1;
}
if(igort<=tram)
{
printf("%dn",igort);
}
else
{
printf("%dn",tram);
}
}
}
}
return 0;
}


 

 

 

最后

以上就是含糊手链为你收集整理的CodeForces 746C Tram的全部内容,希望文章能够帮你解决CodeForces 746C Tram所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部