Codeforces Round #441 (Div.2)
来源:互联网 发布:mac下载os x yosemite 编辑:程序博客网 时间:2024/05/01 05:11
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.
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.
题意:有ROE三个点,每个点都可以吃东西,RO相距a米,RE相距b米,OE相距c米,小熊要吃n次东西,最少要走多少距离,现已知小熊从R点出发(此时已经吃完了第一顿饭),R点吃完后小熊离开R点后还可以再来吃
思路:第一顿在R吃,第二顿在O或E吃(取决于哪个更近),之后就徘徊于最短边两点之间吃东西,才是最佳的
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){ int n,a,b,c; scanf("%d%d%d%d",&n,&a,&b,&c); int mi = min(a,b); mi = min(mi,c); if(n==1) printf("0\n"); else{ int ans = min(a,b); n-=2; ans+=mi*n; printf("%d\n",ans); } return 0 ;}
- Codeforces Round #441 (Div. 2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div. 2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- 【codeforces】Codeforces Round #441(div.2)
- Codeforces Round #441 Div. 2 A
- [刷题]Codeforces Round #441(Div. 2)
- Codeforces Round #441 Div. 2 B
- Codeforces Round #441 Div. 2 E,F
- Codeforces Round #441 (Div. 2) D
- Classroom Watch (Codeforces Round #441 (Div.2) )
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- virtualbox centos7/ubuntu 网络配置
- ProjectForge研究第二天:工程及模块
- Java三方库记录
- 编程检验ASCII码值与字符对应关系 P11
- 第九章0.1解读
- Codeforces Round #441 (Div.2)
- 算数运算符和算术表达式
- Cygwin 和MinGW 的区别与联系是怎样的?
- Codeforces Round #149 (Div. 2) (bfs+STL)
- Fault Injection——持续更新
- 游戏‘微信打飞机 第一课
- 关于win10下搭建kafka0.10的一些坑
- 阿里巴巴Java开发规约插件安装IDEA和Eclipse教程
- Java的单例及多例设计模式