Codeforces Round #441 (Div. 2)A. Trip For Meal模拟水题
来源:互联网 发布:佐治亚南方大学 知乎 编辑:程序博客网 时间:2024/06/05 09:31
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.
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 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.
题意,小熊维尼要去三个朋友abc家中吃饭,第一行输入n代表小熊维尼要吃几顿饭,接下来三行分别是a到b的距离,b到c距离,c到a的距离,然后小熊维尼一开始在A家中,输出小熊维尼吃N次饭最少走多少。
直接模拟就好了。
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;int main(){ int n,a,b,c; cin>>n; cin>>a>>b>>c; int sum=0; int flag=0; for(int i=1;i<n;i++){ if(flag==0){ if(a>b){ sum+=b;flag=1; } else{ sum+=a;flag=2; } } else if(flag==1){ if(b>c){ sum+=c;flag=2; } else{ sum+=b;flag=0; } } else if(flag==2){ if(a>c){ sum+=c;flag=1; } else{ sum+=a;flag=0; } } }cout<<sum<<endl; return 0;}
- Codeforces Round #441 (Div. 2)A. Trip For Meal模拟水题
- Codeforces Round #441 (Div. 2)A. Trip For Meal
- Codeforces Round #441 A. Trip For Meal
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal
- Codeforces Round #441 div2 A. Trip For Meal
- Codeforces 876A. Trip For Meal
- Codeforces 876 A Trip For Meal
- CodeForces 876A Trip For Meal
- Codeforces 876A Trip For Meal 贪心
- Codeforces 876A Trip For Meal
- codeforces 876A Trip For Meal
- Codeforces 876A Trip For Meal 题解
- A. Trip For Meal
- A. Trip For Meal
- CF A. Trip For Meal【water】
- Codeforces Round #297 (Div. 2) A(模拟)
- Codeforces Round #340 (Div. 2)(A) 模拟
- Codeforces876A-Trip For Meal
- 数组在内存中的存储
- 《面试》---Python 实现二叉树结构以及相关遍历
- 关于89C52单片机11.0592M晶振产生115200波特率的方法
- YaHoo!(雅虎)创始人之一 ——— 杨致远
- OpenGL VBO, PBO与FBO
- Codeforces Round #441 (Div. 2)A. Trip For Meal模拟水题
- 文章标题
- HTTP协议详解
- Hibernate使用持久化注解实现多对一映射
- assert and const
- 树莓派GPIO入门08-使用74HC595芯片驱动数码管(二)
- iOS 11 安全区域适配总结
- 利用OPENCV为android开发畸变校正的JNI库
- [行业调研]人工智能简单调研