A. Trip For Meal
time limit per test
memory limit per test
input
output
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is cmeters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n
Winnie-the-Pooh does not like physical activity. He wants to have a meal n
Input
First line contains an integer n (1 ≤ n ≤ 100) — number of visits.
Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.
Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.
Output
Output one number — minimum distance in meters Winnie must go through to have a meal n
Examples
input
3 2 3 1
output
3
input
1 2 3 5
output
0
Note
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
题解:Div2T1应该比较简单,直接模拟就可以了。
Code:
var n,a,b,c,now,i,x,ans,p:longint;标签:begin,end,house,Codeforces876A,Meal,Rabbit,between,now,Trip From: https://blog.51cto.com/u_15888102/5878386
begin
readln(n);
readln(a);
readln(b);
readln(c);
now:=1;
for i:=2 to n do
begin
if now=1 then
begin
if a<b then begin x:=a;p:=2;end
else begin x:=b;p:=3;end;
end;
if now=2 then
begin
if a<c then begin x:=a;p:=1;end
else begin x:=c;p:=3;end;
end;
if now=3 then
begin
if b<c then begin x:=b;p:=1;end
else begin x:=c;p:=2;end;
end;
ans:=ans+x;
now:=p;
end;
writeln(ans);
end.