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 times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).
Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.
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 one number — minimum distance in meters Winnie must go through to have a meal n times.
3 2 3 1
3
1 2 3 5
0
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.
这是codeforces round#441 Div2 的T1啦~
很简单的,题目大意,有三个房子,一开始你在第一个房子里,第一个房子与第二个房子的距离为a,和第三个的距离为b,第二个房子和第三个的距离是c。现在有t个单位的时间,第一时刻你在第一个房子吃饭,每个时刻你要到另一个房子里去吃东西,想当然,作为一个单纯的吃货,当然是多吃少走咯,所以他每次走最短的路径。问要走的最小距离。
p.s.我的代码炒鸡暴力啊,毕竟第一题打卡题也不必要用O(1)算法,这样码的快点啦~
见谅见谅(我只是个翻译员qwq)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{
int n,a,b,c,x,p,ans=0;
scanf("%d%d%d%d",&n,&a,&b,&c);
int now=1;
for(int i=2;i<=n;i++){
if(now==1){
if(a<b) x=a,p=2;
else x=b,p=3;
}
if(now==2){
if(a<c) x=a,p=1;
else x=c,p=3;
}
if(now==3){
if(b<c) x=b,p=1;
else x=c,p=2;
}
ans+=x;now=p;
}
printf("%d\n",ans);
return 0;
}