• 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;
    }
  • 相关阅读:
    Git与GitHub的基本使用
    HTML&CSS基础-外边框
    HTML&CSS基础-内边框
    SHELL脚本编程变量输入
    GoLang基础数据类型-切片(slice)详解
    GoLang基础数据类型--->数组(array)详解
    SHELL脚本编程的运算符
    SHELL脚本编程变量详解
    HTML&CSS基础-边框简写属性
    GoLang基础数据类型--->字符串处理大全
  • 原文地址:https://www.cnblogs.com/JinxiSui/p/9740528.html
Copyright © 2020-2023  润新知