zoukankan      html  css  js  c++  java
  • CF876A Trip For Meal

    题意翻译

    ****非常喜欢蜂蜜! 所以他决定去拜访他的朋友。 **有三个最好的朋友:兔子,猫头鹰和*毛驴,每个人都住在自己的房子里。 每对房屋之间都有蜿蜒的*路。 兔子和猫头鹰的房子之间的路径长度是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;
    }
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    Java实现 LeetCode 242 有效的字母异位词
    Java实现 LeetCode 212 单词搜索 II
    Java实现 LeetCode 212 单词搜索 II
    Java实现 LeetCode 212 单词搜索 II
    Java实现 LeetCode 212 单词搜索 II
    Java实现 LeetCode 344 反转字符串
    Java实现 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk
    Java实现 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk
    Java实现 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk
    Java实现 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/8442672.html
Copyright © 2011-2022 走看看