三种情况:—,列车在人的后面。二,列车与人重合。三,列车宰人的前面。不同情况下比较列车与走路所耗费的时间。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int s,x1,x2,t1,t2,p,d;
cin>>s>>x1>>x2;
cin>>t1>>t2;
cin>>p>>d;
if(t1>=t2)
{
cout<<abs(x1-x2)*t2<<endl;
}
else
{
int opt,time;
if(x1>x2) opt=-1;
else opt=1;
if(opt+d==0)
{
if(d==-1)
time=min((p+x1+abs(x1-x2))*t1,abs(x1-x2)*t2);
else
time=min((s-p+s-x1+abs(x1-x2))*t1,abs(x1-x2)*t2);
cout<<time<<endl;
}
else
{
if(d==-1)
{
if(x1<p&&t1<t2)
{
time=min((p-x2)*t1,(x1-x2)*t2);
}
else if(x1==p)
{
time=min((x1-x2)*t1,(x1-x2)*t2);
}
else
{
time=min((x1-x2)*t2,(p+s+s-x1+x1-x2)*t1);
}
}
else
{
if(x1>p&&t1<t2)
{
time=min((x2-p)*t1,(x2-x1)*t2);
}
else if(x1==p)
{
time=min((x2-x1)*t1,(x2-x1)*t2);
}
else
{
time=min((x2-x1)*t2,(s-p+s+x2)*t1);
}
}
cout<<time<<endl;
}
}
return 0;
}