zoukankan      html  css  js  c++  java
  • CodeForces 371C

    题意

    做汉堡
    先给出一个字符串表示每个汉堡的做法(B:bread, S:sausage, C:cheese)
    给出三个值表示BSC分别有多少存货
    给出三个值表示商店中BSC分别多少钱一份
    给出一个值表示店主现在有多少卢布
    问最多能做多少汉堡

    思路

    二分搜索
    但是中间有很多溢出没处理好
    用的unsigned long long才水过

    AC代码

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    typedef unsigned long long ll;
    const int maxn = 105;
    const ll INF = 0x3f3f3f3f3f3f3f3f;
    char str[maxn];
    ll nb, ns, nc;
    ll pb, ps, pc;
    ll b, s, c;
    ll r;
    
    bool judge(ll mid)
    {
        ll aa = (mid*b-nb)*pb;
        ll bb = (mid*s-ns)*ps;
        ll cc = (mid*c-nc)*pc;
        if(mid*b<=nb) aa = 0;
        if(mid*s<=ns) bb = 0;
        if(mid*c<=nc) cc = 0;
        ll a = aa + bb + cc;
        if( a <= r )
            return true;
        return false;
    }
    
    int main()
    {
        scanf("%s",str);
        int len = strlen(str);
        b = 0, s = 0, c = 0;
        for( int i = 0; i < len; i++ )
        {
            if( str[i] == 'B' ) b++;
            else if( str[i] == 'S' ) s++;
            else if( str[i] == 'C' ) c++;
        }
        scanf("%I64d%I64d%I64d", &nb, &ns, &nc);
        scanf("%I64d%I64d%I64d", &pb, &ps, &pc);
        scanf("%I64d", &r);
        ll ub = INF;
        ll lb = 0;
        while(ub-lb>1)
        {
            ll mid = (ub+lb)/2;
            if( judge(mid) ) lb = mid;
            else ub = mid;
        }
        printf("%I64d
    ", lb);
        return 0;
    }
  • 相关阅读:
    19.将写好的输出到本地 文件格式:Step
    18.对Topo进行打孔
    17.球体
    16.圆柱
    15.绘制圆锥
    14.Chamfer把正方体所有的边倒角
    13.绘制一个方体
    ①②坐标点
    esp8266接线
    IP解析
  • 原文地址:https://www.cnblogs.com/JinxiSui/p/9740528.html
Copyright © 2011-2022 走看看