题意:
人从x1走到x2,每t2秒走1米。车的方向是-1 / 1 每t1秒走1米。询问人打到x2最短时间
思路
分类套路。
pos写的时候智障了,-把车速写成人了
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int s,x1,x2;
cin>>s>>x1>>x2;
int tc,tr;
cin>>tc>>tr;
int pos,to;
cin>>pos>>to;
int from,need;
if(x2<x1)
{
from=-1;
need=x1-x2;
}
else
{
from=1;
need=x2-x1;
}
int dis,dis1,dis2,timec,timer,time3,ans;
dis=0;
if(from==1)
{
// x1 pos x2
if(pos<=x1)
{
if(to==1)
{
timec=(x2-pos)*tc;
timer=need*tr;
}
else
{
timec=(pos+x2)*tc;
timer=(need)*tr;
}
}
else
{
//r c
if(to==1)
{
timec=(s-pos+s+x2)*tc;
timer=need*tr;
}
else
{
timec=(pos+x2)*tc;
timer=need*tr;
}
}
}
else
{
//x2 pos x1
if(pos>=x1)
{ //x2 x1 pos
if(to==1)
{
timec=(s-pos+s-x2)*tc;
timer=need*tr;
}
else
{
timec=(pos-x2)*tc;
timer=need*tr;
}
}
else
{
//x2 pos x1
if(to==1)
{
timec=(s-pos+s-x2)*tc;
timer=need*tr;
}
else
{
timec=(pos+s+s-x2)*tc;
timer=need*tr;
}
}
}
ans=min(timec,timer);
cout<<ans<<endl;
return 0;
}