• codeforces Round #441 A Trip For Meal【思路/模拟】


    A. Trip For Meal
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    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 cmeters.

    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.

    【题意】:一个三角形,给出一个数n和三条边长,要求到达三个点总共n次(不要求每个点都到)。起点固定在R,求走的最短距离。

    【分析】:在最短路上反复横跳(?)。因为反正可以回头。

    【代码】:

    #include <bits/stdc++.h>
    using namespace std;
    int main(void)
    {
        int n,a,b,c;
        scanf("%d%d%d%d",&n,&a,&b,&c);
        if(n==1)
            printf("%d
    ",0 );
        if(n==2)
            printf("%d
    ",min(a,b) );
        if(n>2)
            printf("%d
    ",min(a,b) + min(min(a,b), c)* (n-2) );
    
        return 0;
    }
    View Code
  • 相关阅读:
    Yolo v3代码理解总结
    CRNN数据及标签
    Yolo V3整体实现思路流程详解!
    YOLO V3训练自己的数据集
    Yolo V3理解bbox和label的关系
    深度学习图像扩增
    YOLOv3 K-means获取anchors大小
    CTPN训练自己的数据集过程大白话记录
    浙大版《C语言程序设计(第3版)》题目集 练习4-11 统计素数并求和 (20 分)
    浙大版《C语言程序设计(第3版)》题目集 练习4-10 找出最小值 (20 分)
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7679143.html
Copyright © 2020-2023  润新知