• Xtreme9.0


    Taco Stand

    题目连接:

    https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/taco-stand

    Description

    An editorial for this problem is available at the bottom of this page.

    Joe has been hired to make tacos at a series of baseball games. He wants to calculate the maximum number of tacos he can make based on the available ingredients. He always insists on fresh ingredients, so any leftover ingredients on a given day will be thrown away.

    His ingredients are:

    Taco shells - every taco gets exactly one of these

    Meat

    Rice

    Beans

    His recipe is to take one taco shell, then add exactly two of the ingredients: meat, rice, and beans. So, for example, one taco might have meat and rice, while another taco might be made with rice and beans. However, a taco cannot have two of the same ingredient. For example, Joe will never make a taco with two servings of meat.

    Your task is to write a program to calculate the maximum number of tacos Joe can make each day, given the amount of ingredients he will have.

    Input

    The first line of input is an integer n, 1 <= n <= 1000, specifying how many days Joe will be making tacos.

    The following n lines contain 4 space-separated integers in the format:

    s m r b

    where s is the number of shells available, m is the amount of meat, r is the amount of rice, and b is the amount of beans, each expressed in terms of the number of tacos they could make.

    Note: s, m, r, and b are all non-negative integers less than 109.

    Output

    The output file is exactly n lines long, each line containing an integer specifying the maximum number of tacos Joe can make with that day’s ingredients.

    Note: There is a newline character at the end of the last line of the output.

    Sample Input

    2
    5 3 4 1
    1 9 9 9

    Sample Output

    4
    1

    Hint

    题意

    给你a,b,c,d四个数,你制造一个粮食需要一份a和bcd中的两份,但是bcd中的两份不能一样。

    问你最多制造多少份粮食。

    题解

    考虑bcm,如果最小的+中间的大于最大的,那么答案显然是(b+c+d)/2

    否则答案就是最小的+中间的

    然后再和a取个min就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    void solve()
    {
        long long a[3],b;
        cin>>b;
        for(int i=0;i<3;i++)cin>>a[i];
        sort(a,a+3);
        long long ans = 0;
        if(a[0]+a[1]>a[2])ans=(a[0]+a[1]+a[2])/2;
        else ans=a[0]+a[1];
        cout<<min(b,ans)<<endl;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)solve();
    }
  • 相关阅读:
    Windows 7系统安装MySQL5.5.21图解
    VB中DateDiff 函数解释
    curl命令具体解释
    SecureCRT 6.7.1 注冊机 和谐 破解 补丁 方法
    CSDN--十年
    SxsTrace工具用法
    Gamma校正及其OpenCV实现
    Linux--对文件夹下的配置文件批量改动IP
    sublime配置全攻略
    awk笔记
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5958627.html
Copyright © 2020-2023  润新知