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; }
阅读全文
0 0
- Codeforces Round #386 Div. 2C - Tram
- Codeforces Round #386 (Div. 2)C. Tram
- Codeforces Round #386 (Div. 2) C
- Codeforces Round #386 (Div. 2) C
- Codeforces Round #386 (Div. 2) C. Tram
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #386 (Div. 2)
- Codeforces Round #386 (Div. 2)
- Codeforces Round #386(Div. 2)C. Tram【思维】
- Codeforces Round #386 (Div. 2) A+B+C+D!
- Codeforces Round #386 (Div. 2)C. Tram(模拟+思维)
- Codeforces Round #386 (Div. 2) C. Tram 数学、讨论
- Codeforces Round #386 (Div. 2) 746C Tram
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #137 (Div. 2), problem: (C)
- Codeforces Round #153 (Div. 2) C题
- Codeforces Round #158 (Div. 2) C题
- java基础之一 对象,接口
- 工厂方法模式
- C++ 单生产者多消费者多线程示例
- tcp超时重传
- UML序列图——时序图基本使用
- Codeforces Round #386 (Div. 2) C
- POJ3068 "Shortest" pair of paths
- Maven详解之仓库------本地仓库和远程仓库
- ListView上拉刷新 下拉加载
- Eclipse 运行WordCount实例 (连接Linux下的Hadoop集群)
- git学习心得之2--糟糕操作后的后悔药
- 高通 MSM8K bootloader 之一: SBL1
- Docker在Windows下的安装使用与常见问题
- 自定义评分条(方式一)-CustomRatingBar