Guilty — to the kitchen!
2015-12-07 09:53
621 查看
Description
It’s a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.
According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, …, an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, …, bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately?
Input
The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100).
Output
Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4.
Sample Input
Input
1 100
1
40
Output
40.0
Input
2 100
1 1
25 30
Output
50.0
Input
2 100
1 1
60 60
Output
100.0
题意:让你做汤,第一行n、 V(体积),第二行n个数,表示比例,第三行n个数,表示给你的食材量,让你求最终的体积。
思路:第二行b 除以第一行a,求出最小的 t,然后再把a求和,再乘 t再和V比较。
坑点就是输出时没有告诉你保留几位小数,我看样例是保留一位,然后就一直错。
看一下我的代码吧
It’s a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.
According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, …, an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, …, bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately?
Input
The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100).
Output
Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4.
Sample Input
Input
1 100
1
40
Output
40.0
Input
2 100
1 1
25 30
Output
50.0
Input
2 100
1 1
60 60
Output
100.0
题意:让你做汤,第一行n、 V(体积),第二行n个数,表示比例,第三行n个数,表示给你的食材量,让你求最终的体积。
思路:第二行b 除以第一行a,求出最小的 t,然后再把a求和,再乘 t再和V比较。
坑点就是输出时没有告诉你保留几位小数,我看样例是保留一位,然后就一直错。
看一下我的代码吧
#include <stdio.h> #include <string.h> struct xx { double a, b, mm; }x[100]; int main() { int n, V; while(~scanf("%d %d", &n, &V)) { double ans = 0; for(int i = 0; i < n; i++) { scanf("%lf", &x[i].a); ans += x[i].a; } for(int i = 0; i < n; i++) scanf("%lf", &x[i].b); double min = 2000000; for(int i = 0; i < n; i++) { x[i].mm = x[i].b / x[i].a; if(min > x[i].mm) min = x[i].mm; } ans *= min; if(ans > V) printf("%d\n", V); else printf("%lf\n", ans); } return 0; }
相关文章推荐
- UIPageViewController实现的左右滑动界面
- 根据字符长度动态确定UIlabel宽高
- Code Forces 601 B. Lipshitz Sequence(单调栈)
- iOS设置UIImage的渲染模式:UIImage.renderingMode
- iOS开发-UI控件:日历选取控件
- Android开发-UI控件:Fragment 真正的完全解析(上)
- Android开发-UI控件:实现登陆页面并跳转和简单的注册页面
- UITabBarController
- Hibernate:Query接口中list和iterator区别
- iOS之UI--微博个人详情页
- jboss5+EJB3+MDB Queue
- 第六章 用堆栈视图(Stack Views)来设计UI
- MUI 框架微信支付
- UVA-1626 Brackets sequence
- UESTC 1252 24点游戏 DFS
- Parquet_11. Spark: DataFrames 和 Parquet -- 待完善
- Parquet_10. Spark & Parquet -- 待完善
- CGContextRef UI界面美化
- Parquet_9. 将CSV 文件转换成 Parquet 格式 -- 待完善
- 3.创建简单的UI-Google官网上的Android初学训练