Close Enough Computations

Problem Description
The nutritional food label has become ubiquitous. A sample label is shown to the right. On the label the number of calories and the number of grams of fat, carbohydrate, and protein are given as integers.

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.

 
Input
The input will contain one or more sets of data about potential labels. Each data set will consist of 4 non-negative integers, separated by one or more blanks, on a single line. The integers represent the number of calories, the number of grams of fat, the number of grams of carbohydrates, and the number of grams of protein, in that order. The number of calories will not exceed 10000, and the number of grams of any component will not exceed 1000.

End of input is indicated by a line containing 4 zeroes. This line should not be processed.

 
Output
For each data set, print "yes" or "no" on its own line, indicating whether the given rounded values of the three nutrients can yield the given number of calories.
 
Sample Input
250 12 31 5
250 13 31 5
122 10 10 0
0 0 0 0
 
Sample Output
yes no no

题意:

给你一个检验值,和三个参数值 这三个参数值 分别*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 数学的更多相关文章

  1. UVALive 4192 Close Enough Computations 水题

    Close Enough Computations 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge& ...

  2. 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 ...

  3. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  4. hdu 1577 WisKey的眼神 (数学几何)

    WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. hdu - 3959 Board Game Dice(数学)

    这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...

  6. HDU 5902 GCD is Funny 数学

    GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...

  7. hdu 4946 Just a Joke(数学+物理)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4969 Just a Joke Time Limit: 2000/1000 MS (Java/Others) ...

  8. HDU 5858 Hard problem (数学推导)

    Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...

  9. 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 ...

随机推荐

  1. oracle 11gR2 如何修改 private ip

    1.1    修改 private ip1.1.1  确保crs集群是打开的可以用olsnodes –s 检查集群的状态./olsnodes -sP570a ActiveP570b Active1.1 ...

  2. Java-杂项: Java中Array和ArrayList区别

    ylbtech-Java-杂项: Java中Array和ArrayList区别 1.返回顶部 1. 1)精辟阐述:可以将 ArrayList想象成一种“会自动扩增容量的Array”. 2)Array( ...

  3. IPython Autoreload

    在PyCharm中进行代码调试的时候, 设置修改的模块自动重新载入是非常方便的 In [1]: %load_ext autoreload In [2]: %autoreload 2

  4. BZOJ 3667 Pollard-rho &Miller-Rabin

    论O(1)快速乘和O(logn)快速乘的差距-. //By SiriusRen #include <cstdio> #include <algorithm> using nam ...

  5. ASP.net 中 OutputCache 指令各个参数的作用

    使用@ OutputCache指令 使用@ OutputCache指令,能够实现对页面输出缓存的一般性需要.@ OutputCache指令在ASP.NET页或者页中包含的用户控件的头部声明.这种方式非 ...

  6. javascript中DOM基础知识介绍

    1.1.     基本概念 1.1.1.      DOM DOM Document Object Model 文档对象模型 就是把HTML文档模型化,当作对象来处理 DOM提供的一系列属性和方法可以 ...

  7. iOS开发 小知识点

    1/ iOS汉字百分号互相转换. //汉字 NSString * name = @"时间终于将我对你的爱消耗殆尽"; //汉字转为百分比 NSString * encodeStri ...

  8. cache(缓存)的作用

    cache的作用: 连接文件.内存与应用,为信息流在三者之间流动提供通道: 存储管理:对外与对内: 存取效率: 多线程: 一次存储:分批存储? 系统的缓存控制机制(虚拟内存)使用分段分页与命中机制. ...

  9. MySQL_索引原理与慢查询优化

    索引原理与慢查询优化 创建/删除索引的语法 #方法一:创建表时 CREATE TABLE 表名 ( 字段名1 数据类型 [完整性约束条件…], 字段名2 数据类型 [完整性约束条件…], [UNIQU ...

  10. 路飞学城Python-Day39(第四模块复习题)

    并发编程 一.简答题 1,简述计算机操作系统的中断的作用 由于cpu本身一次只能执行一个程序,操作系统提供的中断机制使得cpu能够实现不断的在各个程序间进行切换,给人的感觉就是多个程序同时执行 为什么 ...