您的位置:首页 > 其它

Codeforces 746C Tram 模拟+思维

2016-12-20 20:34 477 查看
点击打开链接

//t1<t2时:要么直接走到 要么坐车到

//因为坐车第k次经过x2的时间是固定的,所以上车前走了多少步是不重要的.

//人选择坐车时,车要经过x1,人才有可能上车 

#include <bits/stdc++.h>
using namespace std;
const int N=2e4+20;

int main()
{
int s,x1,x2,t1,t2,p,d;
while(cin>>s>>x1>>x2>>t1>>t2>>p>>d)
{

if(t2<=t1)
{
cout<<abs(x2-x1)*t2<<endl;;
}
else
{
int ans=abs(x2-x1)*t2;//by foot
int res=0;//by car
bool flag=false;
//x1,x2,p位置情况比较多,但是s<=1000 一步一步模拟即可
while(1)
{
if(p==x1)
flag=true;
if(p==x2&&flag)
break;

//掉头
if(p==0&&d==-1)
d=1;
if(p==s&&d==1)
d=-1;

p+=d;//
res+=t1;
}
cout<<min(res,ans)<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: