Codeforces Round #441 (Div. 2)A. Trip For Meal
来源:互联网 发布:mysql数据库认证考试 编辑:程序博客网 时间:2024/05/16 06:01
http://codeforces.com/problemset/problem/876/A
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.
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.
题意
Winnie需要吃饭,一天吃n顿,每顿饭在不同的地方吃
Winnie一开始在Rabbit家,Rabbit家距离Owl家a,距离Eeyore家b;Owl家距离Eeyore家c。问Winnie吃n顿饭需最少走多远。
题解
一开始在Rabbit家,所以要想到Eeyore家必须得先到另外两家
在三家来回吃肯定不是最优解(除非距离都一样)
最优的是在距离最近的两家来回倒换
第一种,a*(n-1)
第二种,b*(n-1)
第三种,a+c*(n-2)或者b+c*(n-2)
我们比较这三者大小来确定最优解
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <cmath>using namespace std;#define inf 0x3f3f3f3fint main(){ int n; int a,b,c,ans1,ans2=inf; scanf("%d%d%d%d",&n,&a,&b,&c); ans1=min(a*(n-1),b*(n-1)); if(n>=2) ans2=min(a,b)+c*(n-2); cout << min(ans1,ans2) << endl;}
- Codeforces Round #441 (Div. 2)A. Trip For Meal
- Codeforces Round #441 A. Trip For Meal
- Codeforces Round #441 (Div. 2)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】
- Codeforces876A-Trip For Meal
- Trip For Meal
- Codeforces Round #396(Div. 2)E. Mahmoud and a xor trip【二进制拆位+Dfs处理】
- PAT考试乙级1005(C语言实现)
- python虚拟环境安装和配置
- 以太坊(ETH)挖矿最新教程
- linux中的mysql运用
- BZOJ1789&&BZOJ1830(AHOI2008)[Y型项链]--模拟乱搞
- Codeforces Round #441 (Div. 2)A. Trip For Meal
- CI模型的加载
- XAMPP报错This may be due to a blocked port, missing dependencies
- Twitter营收和用户数量双双回暖,第四季度甚至要开始盈利了
- 股价暴涨13%、贝索斯登顶世界首富原因何在?五大看点全面解读亚马逊2017第三季度财报
- 乂学智适应系统战胜3名17年教龄名师的背后,我们找了创始人栗浩洋聊了聊
- 181. Employees Earning More Than Their Managers
- ImportError: No module named pkg_resources
- vivo X20王者荣耀限量版:首款“撞色”全面屏手机为王者而生!