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();
}
Xtreme9.0 - Taco Stand 数学的更多相关文章
- Xtreme9.0 - Communities 强连通
Xtreme9.0 - Communities 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/c ...
- Xtreme9.0 - Light Gremlins 容斥
Xtreme9.0 - Light Gremlins 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenge ...
- IEEEXtreme Practice Community Xtreme9.0 - Digit Fun!
Xtreme9.0 - Digit Fun! 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/di ...
- Xtreme9.0 - Mr. Pippo's Pizza 数学
Mr. Pippo's Pizza 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/mr-pipp ...
- 51Nod 1003 阶乘后面0的数量(数学,思维题)
1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...
- Xtreme9.0 - Block Art 线段树
Block Art 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/block-art Descr ...
- Xtreme9.0 - Pattern 3 KMP
Pattern 3 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/car-spark Descr ...
- Xtreme9.0 - Car Spark 动态规划
Car Spark 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/car-spark Descr ...
- IEEEXtreme Practice Community Xtreme9.0 - Dictionary Strings
Dictionary Strings 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/dictio ...
随机推荐
- js调试系列: 源码定位与调试[基础篇]
js调试系列目录: - 如果看了1, 2两篇,你对控制台应该有一个初步了解了,今天我们来个简单的调试.昨天留的三个课后练习,差不多就是今天要讲的内容.我们先来处理第一个问题:1. 查看文章下方 推荐 ...
- [转载]AngularJS 开发者最常犯的 10 个错误
http://www.oschina.net/translate/top-10-mistakes-angularjs-developers-make
- 20155314 2016-2017-2 《Java程序设计》第5周学习总结
20155314 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 理解异常架构 牚握try...catch...finally处理异常的方法 会用throw, ...
- 游程编码(Run Length Code)
一.什么是游程编码 游程编码是一种比较简单的压缩算法,其基本思想是将重复且连续出现多次的字符使用(连续出现次数,某个字符)来描述. 比如一个字符串: AAAAABBBBCCC 使用游程编码可以将其描述 ...
- 判断线段之间的关系(D - Intersecting Lines POJ - 1269 )
题目链接:https://vjudge.net/contest/276358#problem/D 题目大意:每一次给你两条直线,然后问你这两条直线的关系(平行,共线,相交(输出交点)). 具体思路:先 ...
- 微信小程序实现首页图片多种排版布局!
先来个效果图: 使用技术主要是flex布局,绝对定位布局,小程序前端页面开发,以及一些样式! 直接贴代码,都有详细注释,熟悉一下,方便以后小程序开发! wxml: <view class='in ...
- kali的中文输入法-安装后无中文选项的解决办法
我在我实体电脑上安装了kali 本想安装个中文输入法但是有时候输入发中根本没有选择输入法的这一项.所以导致很别扭,之前在虚机上安装过没有问题但是挪到实体机上就是没有用的也是fcitx,这一度让我这个小 ...
- mac lsof使用查看端口
安装 brew install lsof 在Mac OS系统中,无法使用netstat来查看端口占用情况,可以使用lsof来代替,这种方式在Linux下也适用. sudo lsof -nP -iTCP ...
- 浅介HTML DOM
什么是DOM? DOM是Document Object Model(文档对象模型)的缩写. DOM是W3C(万维网联盟)的标准. DOM定义了访问HTML和XML文档的标准: “W3C文档对象模型(D ...
- 一步步实现windows版ijkplayer系列文章之一——Windows10平台编译ffmpeg 4.0.2,生成ffplay
一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...