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. [js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解

    路径在canvas绘图中,经常被用到,是一个非常重要的概念. 比如:我们要在canvas画出3条直线,要求用不同的颜色加以区分. <style> body { background: #0 ...

  2. mysql更新某个字符串字段的部分内容

    如果现在需要Mysql更新字段重部分数据,而不是全部数据,应该采用何种方法呢?下面介绍了两种情况下Mysql更新字段中部分数据的方法,供您参考. Mysql更新字段中部分数据第一种情况: update ...

  3. JavaWeb(一)之细说Servlet

    前言 其实javaWeb的知识早就学过了,可是因为现在在搞大数据开发,所以web的知识都忘记了.准备开始慢慢的把Web的知识一点一点的回忆起来,多学一点没有关系,就怕到时候要用的话,什么都不会了. 一 ...

  4. JavaWeb(二)会话管理之细说cookie与session

    前言 前面花了几篇博客介绍了Servlet,讲的非常的详细.这一篇给大家介绍一下cookie和session. 一.会话概述 1.1.什么是会话? 会话可简单理解为:用户开一个浏览器,点击多个超链接, ...

  5. 在CentOS6上编译安装实现LAMP(php-modules)+phpMyAdmin安装过程全记录

    php与apache协作有三种模式:CGI.modules.FastCGI. 在CGI模式下,用户请求php文件时,apache会启动响应进程,调用php处理器处理请求,然后将结果返回给客户端.用户响 ...

  6. 如何在maven pom.xml文件中设置Java编译器版本

    今天遇到一个问题: 在Eclipse中用maven创建一个新的web项目,然后再用maven update一下,则JDK版本自动变为1.5. 通过查找资料,终于发现maven编译器插件(Maven C ...

  7. Ubuntu 16.04 源码编译安装PHP7

    一.下载PHP7的最新版源码 php7.0.9  下载地址 http://php.net/get/php-7.0.9.tar.gz/from/a/mirror 二.解压 tar -zxf /tmp/p ...

  8. Python自学笔记-paramiko模块(Mr serven)

    文章出处:http://www.cnblogs.com/wupeiqi/articles/5095821.html SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: #!/u ...

  9. ZOJ2067 经典 DP

    题目:一个由'.'和'#'组成矩形,统计里面'.'组成的矩形的个数.点击打开链接 自己写挂了,懒得搞了 #include <stdio.h> #include <string.h&g ...

  10. windows mysql 操作实践

    1.通过navicat for mysql 进行数据库表的输入操作. 2.使用mySQL shell进行查询. 3. 显示数据表中的所有列的名称  show colums from user 4. 进 ...