A. Trip For Meal
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard 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 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.

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 times.

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.

每次走最短的距离就行了;

代码写的有点长;

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std; int n,d,b,c,a[][],ans; int main(){
scanf("%d",&n);
n--;
scanf("%d%d%d",&d,&b,&c);
a[][]=d;
a[][]=b;
a[][]=d;
a[][]=c;
a[][]=b;
a[][]=c;
int u=;
for(int i=;i<=n;i++){
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
}
printf("%d",ans);
}

Codeforces A. Trip For Meal的更多相关文章

  1. codeforces Round #441 A Trip For Meal【思路/模拟】

    A. Trip For Meal time limit per test 1 second memory limit per test 512 megabytes input standard inp ...

  2. CF876A Trip For Meal

    CF876A Trip For Meal 题意翻译 小熊维尼非常喜欢蜂蜜! 所以他决定去拜访他的朋友. 小熊有三个最好的朋友:兔子,猫头鹰和小毛驴,每个人都住在自己的房子里. 每对房屋之间都有蜿蜒的小 ...

  3. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal

    http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...

  4. [Codeforces 1037E] Trip

    [题目链接] http://codeforces.com/problemset/problem/1037/E [算法] 首先离线 , 将问题倒过来考虑 , 转化为 : 每次删除一条边 , 此时最多有多 ...

  5. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b, ...

  6. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  7. Codeforces Round #441 (Div. 2)

    Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...

  8. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  9. ACM-ICPC (10/16) Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A. Trip For Meal Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. ...

随机推荐

  1. 团队作业8——第二次项目冲刺(Beta阶段)--5.23 third day

    团队作业8--第二次项目冲刺(Beta阶段)--5.23 third day Day three: 会议照片 项目进展 今天是beta冲刺的第三天,组长回到了队伍当中,正式开始改进alpha中存在的功 ...

  2. 201521123064 《Java程序设计》第7周学习总结

    1. 本章学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 Q1:ArrayList代码分析 1.1 解释ArrayList的contains源 ...

  3. 201521123068 《java程序设计》 第7周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 //contains ...

  4. 201521123020 《Java程序设计》第4周学习总结

    本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. (1)类注释的使用方法是: /** *(要注释的内容) */ (2)学习了Object类,学会了覆 ...

  5. 201521123044 《Java程序设计》第2周作业-Java基本语法与类库

    1. 本章学习总结 ·1.浮点型的不精确,不能简单的像C语言一样用float或者double来定义.在java中有更精确的BigDecimal类. 举例:BigDecimal bd1= new Big ...

  6. 201521123078《Java程序设计》第2周学习总结

    1. 本周学习总结 **学会使用码云管理代码,包括将本地的代码上传至码云,和将码云上的项目保存至本地.编程要掌握重要的类名的使用,提高编程效率,避免想无头苍蝇一样** 2. 书面作业 使用Eclips ...

  7. JAVA课程设计 刘舒婷 201521123096

    1.团队课程设计博客链接 2.个人负责模块说明 2.1 界面菜单的设计: 2.2 录入学生信息: 2.3 对已录入的学生信息进行修改: 3.个人代码提交记录截图 4.自己负责模块或任务详细说明 4.1 ...

  8. JAVA课程设计--------五子棋

    1.团队课程设计博客链接 http://www.cnblogs.com/mz201521044152/p/7065575.html 2.个人负责模块或任务说明 1.重新开始:写一个restartgam ...

  9. 存储过程重置SEQUENCE值从新开始。

    CREATE OR REPLACE PROCEDURE RESET_SEQUENCE( v_SeqName IN VARCHAR2, v_sqlcode OUT NUMBER, v_sqlerrm O ...

  10. 基本的maven的命令行命令

    1.创建简单的maven 的web项目 mvn archetype:create 举例:mvn archetype:create -DgroupId=com.demo.app -DartifactId ...