Codeforces 371C Hamburgers

本文介绍了一道名为“汉堡制作”的编程题,该题要求根据给定的材料数量、价格及预算计算能制作的最大汉堡数量。通过使用二分搜索算法来高效解决此问题。

题目链接:http://codeforces.com/problemset/problem/371/C


题意:做汉堡要3种材料,给出一个字符串表示每种材料要多少,给出每种材料有多少,给出每种材料价格有多少,给出你现在有多少钱,问你最多可以做几个汉堡


思路:最近看到这种题目就立刻想到二分了,二分最多做几个汉堡然后判断钱够不够就可以了,注意有的材料可能不被用到,直接模拟也行,先把原来的材料用完并且做够100个汉堡(材料不够就用钱补,先做够100个防止剩下的材料对购买方案产生影响,初始材料每一样不超过100),然后在判断剩下的钱够几个汉堡就可以了,感觉还是二分比较容易想到


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define inf 2000000000000
#define LL long long
using namespace std;

char ch[130];
int b,s,c,nb,ns,nc,pb,ps,pc;
LL mon;
int judge(LL m)
{
    LL bb=(m*b-nb)*pb,ss=(m*s-ns)*ps,cc=(m*c-nc)*pc;
    if (bb<0) bb=0;
    if (ss<0) ss=0;
    if (cc<0) cc=0;
    if (bb+ss+cc<=mon) return 1;
    else return 0;
}



int main()
{
    while (scanf("%s",&ch)!=EOF)
    {
        int len=strlen(ch);
        b=s=c=0;
        for (int i=0;i<len;i++)
        {
            if (ch[i]=='B') b++;
            else if (ch[i]=='S') s++;
            else if (ch[i]=='C') c++;
        }
        scanf("%d%d%d",&nb,&ns,&nc);
        scanf("%d%d%d",&pb,&ps,&pc);
        scanf("%I64d",&mon);
        LL l=1,r=inf;
        while (l<r)
        {
            LL mid=(l+r)>>1;
            if (judge(mid))
            {
                l=mid+1;
            }
            else
            {
                r=mid;
            }
        }
        printf("%I64d\n",l-1);
    }
}


### Codeforces Problem 1332C Explanation The provided references pertain specifically to problem 742B on Codeforces rather than problem 1332C. For an accurate understanding and solution approach for problem 1332C, it's essential to refer directly to its description and constraints. However, based on general knowledge regarding competitive programming problems found on platforms like Codeforces: Problem 1332C typically involves algorithmic challenges that require efficient data structures or algorithms such as dynamic programming, graph theory, greedy algorithms, etc., depending upon the specific nature of the task described within this particular question[^6]. To provide a detailed explanation or demonstration concerning **Codeforces problem 1332C**, one would need direct access to the exact statement associated with this challenge since different tasks demand tailored strategies addressing their unique requirements. For obtaining precise details about problem 1332C including any sample inputs/outputs along with explanations or solutions, visiting the official Codeforces website and navigating to contest number 1332 followed by examining section C is recommended. ```python # Example pseudo-code structure often seen in solving competitive coding questions. def solve_problem_1332C(input_data): # Placeholder function body; actual logic depends heavily on the specifics of problem 1332C. processed_result = process_input(input_data) final_answer = compute_solution(processed_result) return final_answer input_example = "Example Input" print(solve_problem_1332C(input_example)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值