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();
    }
  • 相关阅读:
    chrome安装HostAdmin app
    Python编码问题
    Elasticsearch利用scroll查询获取所有数据
    oracle不小心更新了数据库中的所有内容后的恢复
    git误提交了项目文件和配置文件的恢复方法
    生成banner的网站
    去除字符串中的emoji字符
    爬虫从网页中去取的数据中包含&nbsp;空格
    高版本的jdk编译过的项目移到低版本的JDK的eclipse中出错的问题
    java爬虫爬取的html内容中空格(&nbsp;)变为问号“?”的解决方法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5958627.html
Copyright © 2011-2022 走看看