码迷,mamicode.com
首页 > 其他好文 > 详细

CF876A Trip For Meal

时间:2018-02-11 20:03:26      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:cout   输入格式   find   for   int   name   div   其他   tween   

题意翻译

小熊维尼非常喜欢蜂蜜! 所以他决定去拜访他的朋友。 小熊有三个最好的朋友:兔子,猫头鹰和小毛驴,每个人都住在自己的房子里。 每对房屋之间都有蜿蜒的小路。 兔子和猫头鹰的房子之间的路径长度是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=1;
int n,a,b,c,ans;
int main(){
    scanf("%d%d%d%d",&n,&a,&b,&c);
    for(int i=1;i<n;i++){
        if(m==1)
            if(a<=b){ ans+=a;m=3; }
            else{ ans+=b;m=2; } 
        else if(m==2)
            if(c<=b){ ans+=c;m=3; }
            else{ ans+=b;m=1; }
        else if(m==3)
            if(a<=c){ ans+=a;m=1; }
            else{ ans+=c;m=2; }
    }
    cout<<ans<<endl;
}

 

CF876A Trip For Meal

标签:cout   输入格式   find   for   int   name   div   其他   tween   

原文地址:https://www.cnblogs.com/cangT-Tlan/p/8442672.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!