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

Xtreme9.0 - Taco Stand 数学的更多相关文章

  1. Xtreme9.0 - Communities 强连通

    Xtreme9.0 - Communities 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/c ...

  2. Xtreme9.0 - Light Gremlins 容斥

    Xtreme9.0 - Light Gremlins 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenge ...

  3. IEEEXtreme Practice Community Xtreme9.0 - Digit Fun!

    Xtreme9.0 - Digit Fun! 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/di ...

  4. Xtreme9.0 - Mr. Pippo's Pizza 数学

    Mr. Pippo's Pizza 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/mr-pipp ...

  5. 51Nod 1003 阶乘后面0的数量(数学,思维题)

    1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5         难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...

  6. Xtreme9.0 - Block Art 线段树

    Block Art 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/block-art Descr ...

  7. Xtreme9.0 - Pattern 3 KMP

    Pattern 3 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/car-spark Descr ...

  8. Xtreme9.0 - Car Spark 动态规划

    Car Spark 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/car-spark Descr ...

  9. IEEEXtreme Practice Community Xtreme9.0 - Dictionary Strings

    Dictionary Strings 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/dictio ...

随机推荐

  1. jQuery总结或者锋利的jQuery笔记一

      在线测试脚本网站 层次 选择器要多花时间看看. 第一章: hover = enter+leave jQuery对象 jQuery产生的对象时jQuery独有的,只能自己调用 var $c=$(&q ...

  2. spark RDD 常见操作

    fold 操作 区别 与 co 1.mapValus 2.flatMapValues 3.comineByKey 4.foldByKey 5.reduceByKey 6.groupByKey 7.so ...

  3. cmd 概览---- 转

    打开"运行"对话框(Win+R),输入cmd,打开控制台命令窗口... 也可以通过cmd /c 命令 和 cmd /k 命令的方式来直接运行命令 注:/c表示执行完命令后关闭cmd ...

  4. html5 canvas在线文本第二步设置(字体边框)等我全部写完,我会写在页面底部

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. [转载]HTML5浏览器测试网站汇总

    http://www.cnblogs.com/javawebsoa/archive/2012/04/19/2458224.html 浏览器支持情况统计 When Can IUse:图表经常更新,展示了 ...

  6. 使用data:uri上传图片

    上传图片的方式有两种,一种是使用传统的html控件的方式,设置form属性为multipart/form-data.这种方式兼容ie6,ie7.另一种方式是使用data:uri,将base64编码从浏 ...

  7. Sublime Text 2 破解 on Mac

    用Sublime Text 2自己打开自己的二进制文件:Sublime Text 2/Contents/MacOS/Sublime Text 2 搜索所有3342 3032 都替换成3242 3032 ...

  8. 第12月第8天 Retrofit.builder

    1. retrofit = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory ...

  9. MongoDB 之 数据类型 最无聊! But 最有用! MongoDB - 3

    MongoDB的新篇章开始啦 - 数据类型 https://www.cnblogs.com/xuzhaocai/p/8048177.html 一.MongoDB 之 丰富多彩的数据类型世界 首先我们要 ...

  10. DSO 优化代码中的 Schur Complement

    接上一篇博客<直接法光度误差导数推导>,DSO 代码中 CoarseInitializer::trackFrame 目的是优化两帧(ref frame 和 new frame)之间的相对状 ...