题意翻译

小熊维尼非常喜欢蜂蜜! 所以他决定去拜访他的朋友。 小熊有三个最好的朋友:兔子,猫头鹰和小毛驴,每个人都住在自己的房子里。 每对房屋之间都有蜿蜒的小路。 兔子和猫头鹰的房子之间的路径长度是a米,兔子和小毛驴的房子之间的距离是b米,猫头鹰的和小毛驴的房子之间的距离是c米。

为了享受圣诞节,维尼想要每天吃n餐饭。 每次维尼都会把每家的蜂蜜都吃完后再离开。 当维尼没有吃满n次时,他会去离他最近的下一家继续吃。 当维尼在一个人家吃饭时,其他人家会重新买来新蜂蜜。 已知现在维尼在兔子家吃的一餐,求维尼要吃满n餐最少要走的路。

第一行包含整数n(1 <= n <= 100 1 <= n <= 100) - 想吃的餐数。 第二行包含一个整数a(1 <= a <= 100 1 <= a <= 100) - 兔子和猫头鹰的房子之间的距离。 第三行包含一个整数b b(1 <= b <= 100 1 <= b <= 100) - 兔子和小毛驴家的距离。 第四行包含一个整数c(1 <= c <= 100 1 <= c <= 100) - 猫头鹰和小毛驴的房子之间的距离。 感谢@Jianuo_Zhu 提供的翻译

题目描述

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 aa meters, between Rabbit's and Eeyore's house is bb meters, between Owl's and Eeyore's house is cc meters.

For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal nn 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 nn times, traveling minimum possible distance. Help him to find this distance.

输入输出格式

输入格式:

First line contains an integer nn ( 1<=n<=1001<=n<=100 ) — number of visits.

Second line contains an integer aa ( 1<=a<=1001<=a<=100 ) — distance between Rabbit's and Owl's houses.

Third line contains an integer bb ( 1<=b<=1001<=b<=100 ) — distance between Rabbit's and Eeyore's houses.

Fourth line contains an integer cc ( 1<=c<=1001<=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 nn times.

输入输出样例

输入样例#1: 复制

3
2
3
1
输出样例#1: 复制

3
输入样例#2: 复制

1
2
3
5
输出样例#2: 复制

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=32+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<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int m=;
int n,a,b,c,ans;
int main(){
scanf("%d%d%d%d",&n,&a,&b,&c);
for(int i=;i<n;i++){
if(m==)
if(a<=b){ ans+=a;m=; }
else{ ans+=b;m=; }
else if(m==)
if(c<=b){ ans+=c;m=; }
else{ ans+=b;m=; }
else if(m==)
if(a<=c){ ans+=a;m=; }
else{ ans+=c;m=; }
}
cout<<ans<<endl;
}

最新文章

  1. Moqui学习之 Step by Step OrderProcureToPayBasicFlow
  2. 关于 CAS 不能登录的问题
  3. 后台获取前台runat=server的select的值
  4. java.net.ServerSocket和java.net.Socket
  5. 「S-A-L-T-A」项目失败总结!
  6. 几个DOM属性
  7. php知识点集合
  8. hdu1556 Color the ball 线段树区间染色问题
  9. 在OpenCV3.1.0中使用SIFT,SURF算法
  10. Linux最小系统移植之早期打印CONFIG_EARLY_PRINTK
  11. MyCP
  12. SpringCloud(6)分布式配置中心Spring Cloud Config
  13. flask 状态保持session和上下文session的区别
  14. python 字典 dict 该注意的一些操作
  15. python 格式话-占位符
  16. Spring3(一) 控制反转(IoC)和依赖注入(DI)
  17. Day 04 if判断,while循环,for循环
  18. 20155211课下测试ch10补交
  19. redis_常用命令
  20. 为什么 Java ArrayList.toArray(T[]) 方法的参数类型是 T 而不是 E ?

热门文章

  1. 记忆化搜索 hdu 1331
  2. DexClassLoader和PathClassLoader类载入机制
  3. wpf Listbox 设置ItemContainerStyle后,ItemTemplateSelector不能触发
  4. 火狐Vimperator插件
  5. 安装MySQL最后一步出现错误Error Nr.1045解决方法
  6. 解决 dotnet core 1.x 命令行(cli) 下运行路径错误
  7. C++中值传递(pass-by-value)和引用传递(pass-by-reference)
  8. .net 获取当前网页的的url
  9. Docker installs
  10. 大白话理解this