A11172 | Trip For Meal
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $c$ meters.
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.
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.
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.
输入输出样例
输入 #1
3 2 3 1
输出 #1
3
输入 #2
1 2 3 5
输出 #2
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted