【水比例】#41 A. Guilty — to the kitchen!

A. Guilty — to the kitchen!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
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

这道题的意思是说有这么多种原料,原料们要按照a[i]的比例来加,问最终最多能做多少升汤

首先用每个b去除以a找到木桶效应的那个短板,就是商最小的那个,记住这个值,然后用这个值来乘以总权值,和V进行比较即可。


#include <queue>
#include <cmath> 
#include <memory> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n,v,index;
	cin>>n>>v;
	pair<double,double> p[21];
	double a[21],b[21];
	memset(a,0,sizeof a);
	for(int i=0;i<n;i++)	cin>>a[i];
	for(int i=0;i<n;i++)	cin>>b[i];
	double min=10009.9;
	for(int i=0;i<n;i++)	
	{
		p[i].first=a[i];
		p[i].second=b[i]/a[i];
		if(min>p[i].second)	min=p[i].second;
	}
	double ans=0.0;
	for(int i=0;i<n;i++)	ans+=p[i].first;
	ans*=min;
	ans =(ans>v?v:ans);
	cout<<ans;
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值