• 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 }
  • 相关阅读:
    原始套接字-自定义IP首部和TCP首部
    原始套接字-TCP/IP下三层数据显示
    ARP欺骗分析
    博弈论
    C++ map & set
    selenium+chrome配置环境
    windows下安装python+selenium
    python之configParser模块读写配置文件
    接口测试流程
    Python之读取文件配置
  • 原文地址:https://www.cnblogs.com/hsd-/p/5464525.html
Copyright © 2020-2023  润新知