【code force】模拟 746C
来源:互联网 发布:socket java 长连接 编辑:程序博客网 时间:2024/06/10 14:54
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2seconds). He can also stand at some point for some time.
The first line contains three integers s, x1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ s, x1 ≠ x2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 ≤ t1, t2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 ≤ p ≤ s - 1, d is either1 or ) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If , the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
4 2 43 41 1
8
5 4 01 23 1
7
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1second. Thus, Igor will reach the point x2 in 7 seconds in total.
题意:一条直线上坐标从0到s,某人从x1到x2;向前走一米需要t2秒,有一辆车子起始位置为p,
向前走一米需要t1秒,车子方向d==1时为正,d==-1时为负,人可以原地不动,等与车子相遇时,人可以坐上车子,问人从x1到x2最少需要多少时间
code:
#include<cstdio>#include<algorithm>using namespace std;int main(){int s,x1,x2,lu1,lu2;int p,d,t1,t2;while(~scanf("%d%d%d",&s,&x1,&x2)){scanf("%d%d",&t1,&t2);scanf("%d%d",&p,&d);if(x2>x1){ lu1=(x2-x1)*t2;//人走所需时间if(d==1){//正向 if(p>x1) lu2=(s-p+s+x2)*t1;else lu2=(x2-p)*t1;}else if(d==-1) lu2=(p+x2)*t1; if(lu1>lu2)printf("%d\n",lu2);else printf("%d\n",lu1); }else{lu1=(x1-x2)*t2;if(d==1) lu2=(s-p+s-x2)*t1;else if(d==-1){if(p<x1)lu2=(p+s+s-x2)*t1;else lu2=(p-x2)*t1;}if(lu1>lu2)printf("%d\n",lu2);else printf("%d\n",lu1); }}return 0; }
- 【code force】模拟 746C
- code force-27C---Unordered Subsequence (模拟+暴力)
- CODE FORCE 500C (New Year Book Reading) (贪心or 模拟)
- code force 449 div2 C. Nephren gives a riddle
- code force 449 div2 C. Nephren gives a riddle
- code force 363B
- code force 828A
- Code Force 229 D (DP)
- Code Force 21B Intersection
- code force 之 Money transfer
- LCIS code force 10D
- HDU6215 Brute Force Sorting 【模拟】
- code force B. Bill Total Value
- code force. Anton and fairy tale.
- code force 429B dp好题
- code force 833B The Bakery
- Code Force 825D Suitable Replacement
- code force 893D Credit Card
- 属性动画入门
- 【JDBC】数据库事务
- Get-GUIDandDeclare
- 请求重定向和请求转发
- 说话习惯
- 【code force】模拟 746C
- 零行代码为 App 添加异常加载占位图
- Linux-常见环境变量及其作用
- 使用非Android系统的其他字体
- 服务器Reactor架构浅析
- 网络编程作业——UDP传输
- excel打开csv文件乱码问题
- 判断一个数是否是2的N次方
- 网络编程作业——UDP传输