zoukankan      html  css  js  c++  java
  • Codeforces 371C Hamburgers

    Description

    Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.

    Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.

    Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.

    Input

    The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).

    The second line contains three integers nb, ns, nc (1 ≤ nb, ns, nc ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pb, ps, pc (1 ≤ pb, ps, pc ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1 ≤ r ≤ 1012) — the number of rubles Polycarpus has.

    Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

    Output

    Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.

    Sample Input

    Input
    BBBSSC
    6 4 1
    1 2 3
    4
    Output
    2
    Input
    BBC
    1 10 1
    1 10 1
    21
    Output
    7
    Input
    BSC
    1 1 1
    1 1 3
    1000000000000
    Output
    200000000001

     

    题意:做汉堡,

    1.输入一串只含 BSC三个英文字母的字符串。表示单个汉堡的组成。

    2.输入3个正整数([1,100]),分别代表现有的 面包,香肠,芝士 的数量。

    3.输入3个正整数([1,100]),分别代表商店里 面包 香肠 芝士的单价。

    4.输入一个整数([1,10^12]),代表其男主角拥有的可购买材料的钱。

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cmath>
     4 #include <stdio.h>
     5 #include <cstring>
     6 #include <string>
     7 #include <cstdlib>
     8 #include <queue>
     9 #include <stack>
    10 #include <set>
    11 #include <vector>
    12 #include <map>
    13 #include <list>
    14 //#include <>
    15 using namespace std;
    16     string s;
    17     char ss[103];
    18     int slen;
    19     int nb,ns,nc;
    20     int pb,ps,pc,pnum; 
    21     long long mon;
    22 struct hum{
    23         int bre;
    24         int sau;
    25         int che;
    26         long long price;
    27     }h[1];
    28 long long money(long long mid)
    29 {
    30     long long a,b,c;
    31     a=mid*h[0].bre-nb;
    32     b=mid*h[0].sau-ns;
    33     c=mid*h[0].che-nc;
    34     if(a<0) a=0;
    35     if(b<0) b=0;
    36     if(c<0) c=0;
    37     
    38     return a*pb+b*ps+c*pc;
    39 }
    40 
    41 int main()
    42 {
    43     //汉堡的组成
    44     cin>>s;
    45     slen=s.length();
    46     strcpy(ss,s.c_str());
    47     //结构体汉堡的初始化 
    48     h[0].bre=0;
    49     h[0].che=0;
    50     h[0].sau=0;
    51     h[0].price=0;
    52     for(int i=0;i<=slen;++i)
    53     {
    54         if(s[i]=='B')
    55             h[0].bre++;
    56         if(s[i]=='C')
    57             h[0].che++;
    58         if(s[i]=='S')
    59             h[0].sau++;        
    60     }
    61     //cout<<h[0].bre<<" "<<h[0].che<<" "<<h[0].sau<<" "<<endl;检测初始化好了没QAQ 
    62     //材料的输入 
    63     scanf("%d%d%d%d%d%d",&nb,&ns,&nc,&pb,&ps,&pc);
    64     h[0].price=pb*h[0].bre+ps*h[0].sau+pc*h[0].che;
    65     cin>>mon;
    66 
    67 //------------材料的处理 
    68     long long l=0,r=1e15,mid=(l+r)/2;
    69     
    70     while(l<r)
    71     {
    72         if(money(mid)<=mon)
    73             l=mid+1;
    74         else
    75             r=mid;
    76         mid=(l+r)/2;
    77      } 
    78     if(money(mid)>mon)
    79         cout<<mid-1<<endl;
    80     else
    81         cout<<mid<<endl;
    82     return 0;
    83 }
    View Code

    ...

  • 相关阅读:
    react-webpack
    react
    重置手机过程
    运用 Node-RED 开发 LoRa 应用
    IBM Node-RED 安装与使用教程
    Node-RED 入门教程:简介
    Thingsboard 3.0 修改 Title、默认语言、主题颜色
    Thingsboard 3.0 通过 tb-gateway 网关接入 MQTT 设备教程
    Thingsboard 入门学习笔记:属性
    ThingsBoard 3.0 版本发布
  • 原文地址:https://www.cnblogs.com/greenaway07/p/10700671.html
Copyright © 2011-2022 走看看