zoukankan      html  css  js  c++  java
  • 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();
    }
  • 相关阅读:
    redis-3.2.5 make 报错
    haproxy 实现多域名证书https
    centos7修改主机名
    ngx_image_thumb模块生成缩略图
    查看nginx在安装时开启了哪些模块
    C# install-package:"xx"已拥有为“xxx”定义的依赖项
    JetBrains 2017/2018全系列产品激活工具
    查看win10版本方法,及win10升级方法
    Windows 10正式版的历史版本
    open '/dev/hwlog_switch' fail -1, 13. Permission denied
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5958627.html
Copyright © 2011-2022 走看看