zoukankan      html  css  js  c++  java
  • Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal

    http://codeforces.com/contest/876/problem/A

    题意:

    一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就继续去另外的朋友家。

    当他在一个朋友家吃的时候,另外的朋友家的蜂蜜就会恢复供应。

    问这个人走的最小的距离。

    一开始因为审题不清楚,忽略了第一次是固定的,所以wa了。

    代码:

     1 #include <stdio.h>
     2 #include <algorithm>
     3 using namespace std;
     4 int main()
     5 {
     6     int n;
     7 
     8     scanf("%d",&n);
     9 
    10     n--;
    11 
    12     int a[3];
    13 
    14     for (int i = 0;i < 3;i++) scanf("%d",&a[i]);
    15 
    16     if (n == 0)
    17     {
    18         printf("0
    ");
    19         
    20         return 0;
    21     }
    22 
    23     int ans = 0;
    24 
    25     if (a[0] < a[1]) ans += a[0];
    26     else ans += a[1];
    27 
    28     n--;
    29 
    30     sort(a,a+3);
    31 
    32     ans += n * a[0];
    33 
    34     printf("%d
    ",ans);
    35 
    36     return 0;
    37 }
  • 相关阅读:
    Annotation
    injector
    Java容器(container)
    build tool(构建工具)maven和gradle安装方法
    version control(版本控制)
    函数式编程
    URI与URL
    超文本传输协议HTTP
    annotation的理解
    Injection
  • 原文地址:https://www.cnblogs.com/kickit/p/7680518.html
Copyright © 2011-2022 走看看