UVALive 4192/HDU 2959 Close Enough Computations 数学
Close Enough Computations
But carefully reading the label may cause the consumer to notice some inconsistencies. A gram of fat has 9 calories, a gram of carbohydrate has 4 calories, and a gram of protein has 4 calories. Consider the label to the right. A simple computation of the number of calories would indicate that the food should contain 12*9 + 31*4 + 5*4 or 252 calories, but the label indicates it has 250 calories.
While sometimes the difference in calories is due to other circumstances (such as the presence of alcohol or soluble fiber), this problem will consider only the possibility of round-off error. This food actually has 12.1 grams of fat (yielding 108.9 calories), 30.6 grams of carbohydrate (122.4 calories), 4.7 grams of protein (18.8 calories), so it does in fact have 250 calories (actually 250.1 calories).
Write a program that will determine if values for a nutritional label are consistent, that is, if there is a way the true values for the grams of nutrients can be rounded to the shown values and yield the number of calories shown.
You should assume that standard rounding rules apply; that is any value less than 0.5 rounds down and those 0.5 or over round up.
End of input is indicated by a line containing 4 zeroes. This line should not be processed.
250 13 31 5
122 10 10 0
0 0 0 0
题意:
给你一个检验值,和三个参数值 这三个参数值 分别*9,*4,*4得到实际值,问你在 参数值可以与实际参数值大小相差在0.5内 的得到的实际值
检验该检验值是否符合标准
题解:
我们把3个参数值都减或加0.5得到最小最大,只要判断 这个需要检验的值是否在 这个范围内就好了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<vector>
using namespace std ;
typedef long long ll; const int N = + ;
const int mod = 1e9 + ; int main() {
double sum,a,b,c;
while(~scanf("%lf%lf%lf%lf",&sum,&a,&b,&c)) {
if(sum == && a == && b == && c == )break;
double mi = max((a - 0.5),0.0) * + max((b - 0.5),0.0) * + max((c - 0.5),0.0) * ;
double ma = (a + 0.5) * + (b + 0.5) * + (c + 0.5) * ;
//printf("%lf %lf \n",sum,mi,ma);
if(sum >= mi &&sum <= ma) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return ;
}
UVALive 4192/HDU 2959 Close Enough Computations 数学的更多相关文章
- UVALive 4192 Close Enough Computations 水题
Close Enough Computations 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge& ...
- 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】
Pokémon GO Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- hdu 1577 WisKey的眼神 (数学几何)
WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu - 3959 Board Game Dice(数学)
这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...
- HDU 5902 GCD is Funny 数学
GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...
- hdu 4946 Just a Joke(数学+物理)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4969 Just a Joke Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5858 Hard problem (数学推导)
Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...
- hdu 4497 GCD and LCM 数学
GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...
随机推荐
- 关于Win 10的隐私保护政策
近日.有人责备Win10收集用户信息,事实上这样的指责并不公平,比方:"Privacy Groups Claim Microsoft Uses Windows 10 as Big Broth ...
- 剑指offer——06旋转数组的最小数字(Python3)
题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数 ...
- 41.使用SAX读取XML
main.cpp #include <QtGui> #include <iostream> #include "saxhandler.h" int main ...
- dubbo 解决既是消费者又是提供者 Duplicate application configs 的问题
首先 有应用A 是 提供者 应用B 来实现既是消费者又是提供者 在应用 B 这边新建两个xml dubbo-consumer.xml 消费者 <!-- 自动扫描注解:通过dubbo实现 - ...
- Qt-窗口部件概念介绍
前言:包括基础窗口部件QWidget.对话框QDialog.QFrame类族 .按钮部件.行编辑器.数值设定框以及滑块部件. 一.基础窗口部件QWidget 窗口部件(Widget)是Qt中建立用户界 ...
- SQL Server数据库性能优化
开篇: 最近遇到了很多性能问题,一直没来的及总结,今天正好周末抽时间总结下: 对于稍微大点的公司或者说用户多一些的公司,说白了就是数据量较大的公司,在查询数据时往往会遇到很多瓶颈.这时就需要 ...
- Swagger中添加Token验证
1.该连接链接到api中基本的swagge功能:http://www.cnblogs.com/hhhh2010/p/5234016.html 2.在swagger中使用验证(这里使用密码验证模式)ht ...
- 安装wampserver遇到的问题及解决方案
丢失api-ms-win-crt-runtime-l1-1-0.dll 安装完wampserver,启动服务器的时候遇到一些问题,提示说缺失dll文件,如下图所示: 网上一搜,很多人出现过丢失api- ...
- ZBrush软件特性之Layers
ZBrush®中的Layers层调控板可以在单个文档工作中添加多个层,实际上是把新建的层作为一个分离的文档,层之间可以相互影响. 使用层工作 Layers调控板为每个层都有预置存放的空间,刚启动ZBr ...
- 凸多边形 HRBUST - 1429 计算几何_凸包_未调完
任选一个点作为起始点,将其他点按与该点连线的极角排序,二分查询点在哪两个射线之间, 并特别判断一下边界即可. Code: #include <cstdio> #include <al ...