Codeforces 746C Tram(水题)
来源:互联网 发布:python xpath教程 编辑:程序博客网 时间:2024/04/28 03:35
题意:在一条直线上,坐标从0到S。 人要从X1位置向X2位置移动,前进一个单位要t2时间。 当人在X1位置,车子在p位置,前进一个单位要t1秒。方向为d,d==1表示从正方向前进, d == -1表示负方向前进。 人可以在与车子相遇时,坐上车子。
题解:亏了,跳过C题去肝D题。貌似这个C更省时间。。。 只要判断一下在满足车子和人至少一次同方向时,谁先到X2位置就好了。
代码如下:
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;int main(){int s,t1,t2,x1,x2,p,d;while(scanf("%d%d%d",&s,&x1,&x2)!=EOF){scanf("%d%d",&t1,&t2);scanf("%d%d",&p,&d);int dix=abs(x2-x1);int time1=dix*t2;int time2;if(d==1){if(p<=x1&&x1<x2)time2=(x2-p)*t1;else if(x1<x2)time2=(s-p+s+x2)*t1;else if(x2<x1)time2=(s-p+s-x2)*t1;}else if(d==-1){if(p>=x1&&x2<x1)time2=(p-x2)*t1;else if(x2<x1)time2=(p+s+s-x2)*t1;else if(x1<x2)time2=(p+x2)*t1;}if(time2>time1)printf("%d\n",time1);elseprintf("%d\n",time2);} return 0;}
0 0
- codeforces 746 C. Tram【水题】
- Codeforces 746C Tram(水题)
- CodeForces 746C Tram
- 746 C. Tram codeforces
- codeforces 746 C. Tram
- 【30.43%】【codeforces 746C】Tram
- 【Codeforces 746 C Tram】+ 细节
- Codeforces #386 C 746 C Tram
- Codeforces 746C Tram 模拟+思维
- Codeforces Round #386 (Div. 2) 746C Tram
- Codeforces Round #386 Div. 2C - Tram
- Codeforces Round #386 (Div. 2)C. Tram
- Codeforces Round #386 (Div. 2) C. Tram
- Codeforces Round #386(Div. 2)C. Tram【思维】
- Codeforces Round #386 (Div. 2)C. Tram(模拟+思维)
- Codeforces Round #386 (Div. 2) C. Tram 数学、讨论
- CodeForces-116A-Tram
- CodeForces 116A Tram
- 欢迎使用CSDN-markdown编辑器
- ScrollView和ListView嵌套显示不完全
- Windows下vs2015编译Chromium[2016/12/18]
- PHPStorm+XDebug进行调试图文教程
- Leetcode Lowest Common Ancestor of a Binary Search Tree
- Codeforces 746C Tram(水题)
- Zen Coding 快速编写HTML/CSS代码的实现
- vovado 2014.4 IP核之Clocking Wizard实现分频与倍频
- zen coding 教程zen coding实例
- listView多条目显示
- Retrofit中使用@PartMap实现带进度回调的文件上传
- 图的最短路算法
- Codeforces 746D Green and Black Tea(构造)
- python--字符串操作