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 ≤ 1000, 0 ≤ 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 - 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 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 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.

题意     0到s线段中给出两个点x1和x2,从x1到x2,然后可以坐车,车开始在p点车头方向为d(d==1向右 d==-1向左),

汽车在0-S之间不停地开,到达0或S点会掉头,人可以在任意时间上、下车,汽车每t1秒走1,步行每t2秒走1,问人从x1到x2的最短时间。

官方解析

It is easy to show that if Igor faster than the tram the answer is |x1 - x2|·t2.

In the other case we need to use the following hint: the time of arrive does not depend on how much Igor walk before enter the tram, if the tram will reach the finish point faster than Igor. So Igor can wait the tram in the point x1.

The answer is minimum of the following values: the time during which Igor will reach the point x2 by foot and the time during which the tram will reach at first the point x1 and than the point x2.

这要比较汽车先经过x1再经过x2所花的时间和人从x1走到x2所花的时就可以了,然后分类讨论前者的情况 共有六种情况(注意合并后)。

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= ;
const int maxm= 1e9+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int main()
{
int s,x1,x2,t1,t2,d,p;
scanf("%d %d %d",&s,&x1,&x2);
scanf("%d %d",&t1,&t2);
scanf("%d %d",&p,&d);
int ans1,ans2;
ans1=abs(x1-x2)*t2;
if(d==)              //向右三种
{
if(p<=x1&&x2>x1)
ans2=(x2-p)*t1;
else if(x2>x1)
ans2=(s-p+s+x2)*t1;
else if(x2<x1)
ans2=(s-p+s-x2)*t1;
}
else                //向左三种
{
if(p>=x1&&x2<x1)
ans2=(p-x2)*t1;
else if(x2<x1)
ans2=(p+s+s-x2)*t1;
else if(x2>x1)
ans2=(p+x2)*t1;
}
printf("%d\n",min(ans1,ans2)); //取两者最小
}

codeforces 746C 模拟的更多相关文章

  1. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  2. CodeForces - 404B(模拟题)

    Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  3. Codeforces 709B 模拟

    B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  4. CodeForces - 404A(模拟题)

    Valera and X Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit ...

  5. Codeforces 390A( 模拟题)

    Inna and Alarm Clock Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64 ...

  6. Codeforces 452D [模拟][贪心]

    题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...

  7. CodeForces - 796B 模拟

    思路:模拟移动即可,如果球落入洞中停止移动.注意:有可能第一个位置就是洞!! AC代码 #include <cstdio> #include <cmath> #include ...

  8. CodeForces - 864C-Bus-(模拟加油站问题)

    https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解 ...

  9. Codeforces 709C 模拟

    C. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...

随机推荐

  1. python for循环巧妙运用(迭代、列表生成式)

    200 ? "200px" : this.width)!important;} --> 介绍 我们可以通过for循环来迭代list.tuple.dict.set.字符串,di ...

  2. 使用 webpack 打包 font 字体的问题

    之前在使用 Vue 做项目的时候使用了 font 字体,然而在打包的时候 font 字体的引用路径不正确. 解决办法就是在 webpack 的配置文件中设置根路径 目录在 \config\index. ...

  3. java 设计模式-缺省适配器模式

    本文转载地址:http://www.cnblogs.com/iyangyuan/archive/2013/03/11/2954808.html 在程序设计过程中,读者很可能遇到这样一种困境:设计了一个 ...

  4. 9.11 test

    题面.pdf T1:通过打表发现,从一个点出发只有距离为1,2,3,5,6,9,10,13,17的点才不能到达: 那么我们转移的时候只有距离在20以内才不一定能直接转移,那么我们离散化之后; 对于每一 ...

  5. 【bzoj3809】Gty的二逼妹子序列

    Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们 ...

  6. PHP随机函数【上】

    随机函数应用的场景很多,比如验证码,token,订单号等.由浅入深了解常用随机函数 1.rand 常用的随机数字函数,默认生成[0,getrandmax()]之间的随机数(包括边界值),因性能问题已被 ...

  7. 详细的DedeCMS(织梦)目录权限安全设置教程

    一.目录权限根据统计,绝大部分网站的攻击都在根目录开始的,因此,栏目目录不能设置在根目录.DEDECMS部署完成后,重点目录设置如下:1)将install删除.2) data.templets.upl ...

  8. calling c++ from golang with swig--windows dll (三)

    calling c++ from golang with swig--windows dll 三 使用动态链接库(DLL)主要有两种方式:一种通过链接导入库,在代码中直接调用DLL中的函数:另一种借助 ...

  9. Bilateral Filter

    最近在看图像风格化的论文的时候,频繁遇到 Bilateral Filter.google 一波后,发现并不是什么不得了的东西,但它的思想却很有借鉴意义. 简介 Bilateral Filter,中文又 ...

  10. RSA加解密实现

    RSA是由MIT的三位数学家R.L.Rivest,A.Shamir和L.Adleman[Rivest等1978, 1979]提出的一种用数论构造双钥的方法,被称为MIT体制,后来被广泛称之为RSA体制 ...