Codeforces Round #386(Div. 2)C. 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 x1and 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.


题目大意:

一个长度为S的隧道,0为最左边,S为最右边,电车是一直在动的,每t1s走1m,如果撞倒了边界,就会马上掉头行驶不会停下来,人是随意选择行走方式的(可以逆向,可以停下来,怎么走都行),每t2s走1m.这个人初始位子在x1.想要到位子x2处,问他从x1到x2的最短时间.人上车必须在整数米处才可以上车。


思路:


1、我们分类讨论,如果人的速度比车子的速度快,那么很明显我们直接走过去就行了。


2、如果人的速度没有车子的速度快,那么我们人只要停在原地等着车过来就行了,因为无论我们是逆行去找车,还是顺着走等车,其实都是在等车,而且某些情况我们走了之后还要等车子多走几圈才能接到人,那么我们不如原地等着车过来即可。

那么我们此时就要比较:

①人直接从x1走到x2的时间

②车子经过x1之后再到x2的时间

两者的大小,取最小即为答案。


Ac代码:


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll __int64
ll n,ss,tt;
ll t1,t2;
ll pos,d,output;
void init()
{
    int flag=0;
    ll tim=0;
    while(1)
    {
        if(pos==ss)
        {
            if(flag==0)flag=1;
        }
        if(pos==tt)
        {
            if(flag==1)
            {
                output=min(output,tim);
                break;
            }
        }
        if(pos==n&&d==1||pos==0&&d==-1)
        {
            d=-d;
            pos+=d;
            tim+=t1;
        }
        else
        {
            pos+=d;
            tim+=t1;
        }
    }
}
int main()
{
    while(~scanf("%I64d%I64d%I64d",&n,&ss,&tt))
    {
        scanf("%I64d%I64d",&t1,&t2);
        scanf("%I64d%I64d",&pos,&d);
        if(t1<t2)
        {
            output=abs(ss-tt)*t2;
            init();
            printf("%I64d\n",output);
        }
        else
        {
            output=abs(ss-tt)*t2;
            printf("%I64d\n",output);
        }
    }
}






# 高校智慧校园解决方案摘要 智慧校园解决方案是针对高校信息化建设的核心工程,旨在通过物联网技术实现数字化校园的智能化升级。该方案通过融合计算机技术、网络通信技术、数据库技术和IC卡识别技术,初步实现了校园一卡通系统,进而通过人脸识别技术实现了更精准的校园安全管理、生活管理、教务管理和资源管理。 方案包括多个管理系统:智慧校园管理平台、一卡通卡务管理系统、一卡通人脸库管理平台、智能人脸识别消费管理系统、疫情防控管理系统、人脸识别无感识别管理系统、会议签到管理系统、人脸识别通道管理系统和图书馆对接管理系统。这些系统共同构成了智慧校园的信息化基础,通过统一数据库和操作平台,实现了数据共享和信息一致性。 智能人脸识别消费管理系统通过人脸识别终端,在无需接触的情况下快速完成消费支付过程,提升了校园服务效率。疫情防控管理系统利用热成像测温技术、视频智能分析等手段,实现了对校园人员体温监测和疫情信息实时上报,提高了校园公共卫生事件的预防和控制能力。 会议签到管理系统和人脸识别通道管理系统均基于人脸识别技术,实现了会议的快速签到和图书馆等场所的高效通行管理。与图书馆对接管理系统实现了一卡通系统与图书馆管理系统的无缝集成,提升了图书借阅的便捷性。 总体而言,该智慧校园解决方案通过集成的信息化管理系统,提升了校园管理的智能化水平,优化了校园生活体验,增强了校园安全,并提高了教学和科研的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值