codeforces 746 C. Tram【水题】
2016-12-19 00:57
519 查看
C. Tram
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 1 meter 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 t2 seconds).
He can also stand at some point for some time.
Input
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
either 1 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.
Ifd = 1, the tram goes in the direction from the point 0 to
the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to
the point x2.
Examples
input
output
input
output
Note
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 8 seconds
in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and
get to the point 1 in 6 seconds
(because he has to pass 3meters, 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 1meter in 1 second.
Thus, Igor will reach the point x2 in 7 seconds
in total.
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 1 meter 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 t2 seconds).
He can also stand at some point for some time.
Input
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
either 1 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.
Ifd = 1, the tram goes in the direction from the point 0 to
the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to
the point x2.
Examples
input
4 2 4 3 4 1 1
output
8
input
5 4 0 1 2 3 1
output
7
Note
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 8 seconds
in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and
get to the point 1 in 6 seconds
(because he has to pass 3meters, 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 1meter in 1 second.
Thus, Igor will reach the point x2 in 7 seconds
in total.
/* 题意:给你s,x1,x2,t1,t2,p,d,分别表示一段路的长度(从0~s),你的起点和终点,汽车每t1秒跑1m,你每t2秒跑1m, 汽车刚开始在点p,方向是d(1表示向右,-1表示向左),汽车每次到达端点都会瞬间往回走,不断往返,你可以 在任何时候上车或者下车,问你到达终点需要最少多少时间 类型:水题 分析:追来追去的,分类讨论,考虑仔细点就行 */ #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; }
相关文章推荐
- codeforces 746 A.Compote【水题】
- codeforces 746 B. Decoding【水题】
- codeforces 746 C. Tram
- 【Codeforces 746 C Tram】+ 细节
- 【codeforces】Codeforces Round #280 (Div. 2) 水题专场
- CodeForces 482A-构造水题
- Codeforces 66B:Petya and Countryside(水题)
- codeforces 10月1日 A题 TL--水题
- Codeforces 599A Patrick and Shopping 【水题】
- codeforces 676A (水题)
- Codeforces-859A - Declined Finalists - 水题
- Codeforces 368B:Sereja and Suffixes(水题)
- CodeForces-787B(题目不好读懂,懂了题目就发现是水题,感觉自己棒棒哒)
- CodeForces 919A Supermarket(水题)
- CodeForces 706A Beru-taxi 【水题】
- CodeForces 560A Currency System in Geraldion 【水题】
- CodeForces--606A --Magic Spheres(模拟水题)
- Codeforces 845C Two TVs【思维】水题
- Codeforces 851A - Arpa and a research in Mexican wave - 水题
- 733B Parade codeforces(水题)