zoukankan      html  css  js  c++  java
  • CodeForces 42A Guilty — to the kitchen!

     Guilty — to the kitchen!
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    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
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 struct Node
     6 {
     7     double a;
     8     double b;
     9     double c;
    10 }s[25];
    11 
    12 bool cmp(Node x,Node y)
    13 {
    14     return x.c<y.c;
    15 }
    16 int main()
    17 {
    18     int n,i,j;
    19     double a[25],b[25],c[25],v;
    20     while(scanf("%d %lf",&n,&v)!=EOF)
    21     {
    22         for(i=1;i<=n;i++)
    23             scanf("%lf",&s[i].a);
    24         for(i=1;i<=n;i++)
    25         {
    26             scanf("%lf",&s[i].b);
    27             s[i].c=s[i].b/s[i].a;
    28         }
    29         sort(s+1,s+n+1,cmp);
    30         double ans=0;
    31         for(i=1;i<=n;i++)
    32             ans=ans+s[1].c*s[i].a;
    33         if(ans>v)
    34             ans=v;
    35         printf("%lf
    ",ans);
    36     }
    37     return 0;
    38 }
    View Code
  • 相关阅读:
    spring 注解学习 一 Bean的注入
    jdk动态代理详解 二 代理失效
    jdk动态代理详解 一 入门
    tomcat中web应用的目录结构
    mongoose与mongodb 的版本兼容性表格
    树莓派3B安装ffmpeg过程记录
    ESP8266驱动SSD1306 ESP8266 for Arduino(NodeMCU U8G2库)
    ESP8266 for Arduino开发环境安装
    Mongodb3.4升张到4.0过程
    使用webgl(three.js)创建自动化抽象化3D机房,3D机房模块详细介绍(抽象版一)
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771510.html
Copyright © 2011-2022 走看看