Codeforces Round #441 Div. 2 A
来源:互联网 发布:手机全民k歌没有网络 编辑:程序博客网 时间:2024/05/22 07:49
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 isb meters, between Owl's and Eeyore's house isc meters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a mealn 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 mealn times.
3231
3
1235
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 distance2 + 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.
题目意思是 小熊从 Rabbit的家去其他人家吃蜂蜜,一天要吃n次,在另外的一家(一共就三家)吃完之后还可以重新回来吃, 问你吃完n次的最短路径;
#include<bits/stdc++.h>using namespace std;int main(){ int a,b,c,n; cin>>n>>a>>b>>c; int mmp[5][5]; mmp[0][0]=mmp[1][1]=mmp[2][2] = 1e9; mmp[0][1]=mmp[1][0]=a; mmp[1][2]=mmp[2][1]=c; mmp[0][2]=mmp[2][0]=b; n--; int now = 0,res=0; while(n--){ int pos,minn=1e9; for(int i=0;i<3;i++){ if(mmp[now][i]<minn){ pos=i; minn = mmp[now][i]; } } res+=minn; now = pos; } cout<<res<<endl; return 0;}
- Codeforces Round #441 Div. 2 A
- Codeforces (441A) Round #252 (Div. 2) A题
- Codeforces Round #441 (Div. 2) A,B,C
- Codeforces Round #441 (Div. 2)A + B + C
- Codeforces Round #441 (Div. 2)A. Trip For Meal
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #173 (Div. 2) A.Bit++
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- Codeforces Round #133 (Div. 2) A题
- Codeforces Round #137 (Div. 2) A题
- Codeforces Round #138 (Div. 2) A题
- 牛客网刷题笔试1(java)
- ccproxy网络代理服务器配置
- C++随笔——悬空指针
- 微服务概念
- 欢迎使用CSDN-markdown编辑器
- Codeforces Round #441 Div. 2 A
- 同步通信和异步通信的爱恨情仇
- c++实现链式表的类模板
- Html基础编译知识
- 树状数组
- hdu 4821(字符串hash)
- 小白如何使用新版的oracle官方文档
- 《人民的名义》小结
- Rsync配置文件详解2