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 s, x1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ s, x1 ≠ 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 - 1, d 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 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 x2 in 7 seconds in total.

/*
D题Debug调了20分钟有点炸,C题才没出。但是好在有惊无险的上分了(维持稳定的上分节奏,非常好)
分开求,一种是人的不坐车,另一种就是坐车,而坐车的时候实际就是求车走的时间
*/
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int main(){
//freopen("in.txt","r",stdin);
int s,x1,x2,t1,t2,p,d1,d2;
scanf("%d%d%d%d%d%d%d",&s,&x1,&x2,
&t1,&t2,
&p,&d1);
//车速比人慢直接没有坐车的必要
//if(t1>=t2){
// printf("%d\n",abs(x1-x2)*t1);
// return 0;
//}
//剩下的只是车比人快
/*
情况1:不坐车
*/
int time1=abs(x1-x2)*t2;
/*
情况2:坐车(实际就是求车到达x2的时间
*/
if(x1-x2<) d2=;
else d2=-;
int step=;//模拟车走过的米数
int x=p;//记录车的位置
int flag1=,flag2=;//记录车是不是从x1开到x2的
if(x==x1) flag1=;
if(flag1&&x==x2) flag2=;//必须是从x1开过来的并且开到了x2车才能记录下来
while(true){
//cout<<x<<endl;
if(flag2) break;
if(x==&&d1==-) d1=;//掉头
if(x==s&&d1==) d1=-;//掉头
x+=d1;
step++;
if(x==x1) flag1=;
if(flag1&&x==x2) flag2=;//必须是从x1开过来的并且开到了x2车才能记录下来
}
int time2=t1*step;
//cout<<time1<<" "<<time2<<endl;
printf("%d\n",min(time1,time2));
return ;
}

Codeforces Round #386 (Div. 2) C. Tram的更多相关文章

  1. Codeforces Round #386 (Div. 2) A+B+C+D!

    A. Compote 水题(数据范围小都是水题),按照比例找最小的就行了,3min水过. int main() { int a,b,c; while(~scanf("%d%d%d" ...

  2. Codeforces Round #386 (Div. 2)

    迟到的一次比赛 最近状态很崩溃 网速很慢 然后前面五题看了都有打 但是 只有A B E 是过了的 是时候要反省一下 A.随便判断一下就好 最少的份数嘛 B.画出来之后是一下子左边一下子右边 打一个递归 ...

  3. Codeforces Round #386 (Div. 2) C D E G

    一场比较简单的题 比较脑洞 C 如果坐车比较快的话 先走不如等车 所以最后的ans是min(纯走路,纯坐车) 讨论一下坐车时间 D 因为k一定是>=1的 所以当a=b的时候 GBGBGB这样间隔 ...

  4. Codeforces Round #386 (Div. 2) 746F(set的运用)

    题目大意 给出一个歌单(有n首歌),每个歌都有愉悦值和时间,你可以选择从第x首歌开始听(也就是选择连续的一段),并且你可以选择w首歌让它的时间减半,限制时间为k,求最大的愉悦值 首先我们需要贪心一下, ...

  5. Codeforces Round #386 (Div. 2) 746G(树的构造)

    大体题意 一棵树有n个结点,告诉你每层深度上有a[i]个结点,以及有多少叶子结点 让你生成这棵树 题解:考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那么答案很简单,就是对(a[ ...

  6. Codeforces Round #386 (Div. 2)G. New Roads [构造][树]

    题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那 ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. angular directive自定义指令

    先来看一下自定义指令的写法 app.directive('', ['', function(){ // Runs during compile return { // name: '', // pri ...

  2. grunt学习笔记1 理论知识

    你需要检查js语法错误,然后再去压缩js代码.如果这两步你都去手动操作,会耗费很多成本.Grunt就能让你省去这些手动操作的成本. “—save-dev”的意思是,在当前目录安装grunt的同时,顺便 ...

  3. windows下创建Python虚拟环境

    windows下创建Python虚拟环境 说明 由于Python的版本众多,还有Python2和Python3的争论,因此有些软件包或第三方库就容易出现版本不兼容的问题. 通过 virtualenv ...

  4. javascript的数值转换 number()详解

    ---恢复内容开始--- number() parseInt() parseFloat()这三个函都可以把数非数值转换为数值,我们看看他们的区别在哪里 一 Number() 转型函数Number()是 ...

  5. 深入理解C# 静态类与非静态类、静态成员的区别 [转载]

    静态类 静态类与非静态类的重要区别在于静态类不能实例化,也就是说,不能使用 new 关键字创建静态类类型的变量.在声明一个类时使用static关键字,具有两个方面的意义:首先,它防止程序员写代码来实例 ...

  6. Angular - 预加载 Angular 模块

    Angular - 预加载延迟模块 在使用路由延迟加载中,我们介绍了如何使用模块来拆分应用,在访问到这个模块的时候, Angular 加载这个模块.但这需要一点时间.在用户第一次点击的时候,会有一点延 ...

  7. java泛型使用总结

    1. 泛型方法: 2. 泛型类: 3. 通配符. 1.泛型方法 泛型方法在调用时可以接收不同类型的参数.根据传递给泛型方法的参数类型,编译器适当地处理每一个方法调用. 下面是定义泛型方法的规则: 所有 ...

  8. #云栖大会# 移动安全专场——APP加固新方向(演讲速记)

    主持人导语: 近些年来,移动APP数量呈现爆炸式的增长,黑产也从原来的PC端转移到了移动端,伴随而来的逆向攻击手段也越来越高明.在解决加固产品容易被脱壳的方案中,代码混淆技术是对抗逆向攻击最有效的方式 ...

  9. ora-01440:要减小精度或标度,则要修改的列必须为空

    --由于业务需求变更,需要对oracle数据库productinfo表的productPrcie结构进行修改.修改表结构,必须是在表空的情况下才可以修改表结构.具体操作步骤: --1.查看produc ...

  10. python重试(指数退避算法)

    本文实现了一个重试的装饰器,并且使用了指数退避算法.指数退避算法实现还是很简单的.先上代码再详细解释. 1.指数退避算法 欠奉.http://hugnew.com/?p=814 2.重试装饰器retr ...