Codeforces Round #386 (Div. 2) C

来源:互联网 发布:jsp引入java 编辑:程序博客网 时间:2024/06/10 13:36

自己当初做的时候做麻烦了,而且做不对

看了题解之后豁然开朗

什么时候上车没区别 这一点很关键

假如人走10秒 车走8秒 一定要从x1到x2   在x1到x2的过程中,人还没到,无论走还是不走,车一定会经过人的,这样简单许多

但刚刚有卡在 x1 p x2 

后来一想,如果人能在x2之前追上车,就不用乘车了

综上,最小值是人走和车从p 但必须从x1到x2的最小值

代码如下

#include <cstdio>  #include <algorithm>  #include <cstdlib>  #include <cmath>  using namespace std;  int main() {      int n,x1,x2,t1,t2,p,d;      scanf("%d%d%d%d%d%d%d",&n,&x1,&x2,&t1,&t2,&p,&d);      int man=abs(x2-x1)*t2,s=0,ans=0;      if(d>0) {          if(p<=x1 && x1<x2) s=x2-p;          else if(x1<=p && p<=x2) s=2*(n-p)+2*p+(x2-p);          else if(x1<x2 && x2<=p) s=2*(n-p)+p+x2;          else if(p<=x2 && x2<x1) s=(n-p)+(n-x2);          else if(x2<=p && p<=x1) s=2*(n-p)+p-x2;          else if(x2<x1 && x1<=p) s=n-p+(n-x2);          ans = min(s*t1, man);      } else {          if(p<=x1 && x1<x2) s=p+x2;          else if(x1<=p && p<=x2) s=p+x2;          else if(x1<x2 && x2<=p) s=p+x2;          else if(p<=x2 && x2<x1) s=p+n+(n-x2);          else if(x2<=p && p<x1) s=p+n+(n-x2);          else if(x2<x1 && x1<=p) s=p-x2;          ans = min(s*t1, man);      }      printf("%d", ans);      return 0;  }  


原创粉丝点击