zoukankan      html  css  js  c++  java
  • Codeforces Round #350 (Div. 2) D1

    D1. Magic Powder - 1
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.

    Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.

    Apollinaria has bi gram of the i-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the n ingredients and can be used for baking cookies.

    Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.

    Input

    The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.

    The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie.

    The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

    Output

    Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

    Examples
    Input
    3 1
    2 1 4
    11 3 16
    Output
    4
    Input
    4 3
    4 3 5 6
    11 12 14 20
    Output
    3
    Note

    In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.

    In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.

    题意:做一块曲奇需要n种原料 做一块需要每种a1..a2..an克    现拥有b1...bn每种原料 以及k克魔法面粉(可以代替1:1任何原料)

            问 最多能做多少块曲奇?

    题解: for循环暴力处理  每块每块地做

     1 #include<bits/stdc++.h>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<queue>
     6 #include<stack>
     7 #include<map> 
     8 #define ll __int64
     9 #define pi acos(-1.0)
    10 using namespace std;
    11 int n,k;
    12 
    13 struct node
    14 {
    15     int a;
    16     int b;
    17 }N[1005];
    18 int ans;
    19 int main()
    20 {
    21     scanf("%d %d",&n,&k);
    22      for(int i=1;i<=n;i++)
    23      scanf("%d",&N[i].a);
    24      for(int i=1;i<=n;i++)
    25      scanf("%d",&N[i].b);
    26      ans=0;
    27      for(int j=1;j<=2000;j++)
    28      {
    29          for(int i=1;i<=n;i++)
    30          { 
    31             if(N[i].b>=N[i].a)
    32              N[i].b=N[i].b-N[i].a;    
    33           else
    34           {
    35                 k=k-(N[i].a-N[i].b);
    36                 N[i].b=0;
    37           }
    38           if(i==n&&k>=0)
    39            ans++;
    40         }
    41         if(k<=0)
    42         break;
    43      }
    44      printf("%d
    ",ans);
    45     return 0;
    46 }
  • 相关阅读:
    CODING DevOps 高级架构师王炜入选木兰开源社区首批导师
    夯实基础,踏步云升 | 云原生 DevOps 入门必读
    Cloud Studio 2.0:云的开端
    持续演进的云原生应用交付
    CODING 携手 CoDesign:让设计与开发更简单
    代码扫描 | 把控代码质量的利器
    CODING 持续集成 | 自定义插件,满足你多样化的构建需求
    随便侃侃博客挖坑的事
    如何解决快应用页面滑动卡顿问题
    【HMS Core 6.0全球上线】华为3D建模服务(3D Modeling Kit),轻松构建高质量3D模型
  • 原文地址:https://www.cnblogs.com/hsd-/p/5464525.html
Copyright © 2011-2022 走看看