Xtreme9.0 – Taco Stand 数学

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();
}

原文链接: https://www.cnblogs.com/qscqesze/p/5958627.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    Xtreme9.0 - Taco Stand 数学

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/242052

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 下午10:04
下一篇 2023年2月13日 下午10:06

相关推荐