CodeForces- 371C Hamburgers

#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <list>
//#include <>
using namespace std;
    string s;
    char ss[103];
    int slen;
    int nb,ns,nc;
    int pb,ps,pc,pnum; 
    long long mon;
struct hum{
        int bre;
        int sau;
        int che;
        long long price;
    }h[1];
long long money(long long mid)
{
    long long a,b,c;
    a=mid*h[0].bre-nb;
    b=mid*h[0].sau-ns;
    c=mid*h[0].che-nc;
    if(a<0) a=0;
    if(b<0) b=0;
    if(c<0) c=0;
    
    return a*pb+b*ps+c*pc;
}

int main()
{
    //汉堡的组成
    cin>>s;
    slen=s.length();
    strcpy(ss,s.c_str());
    //结构体汉堡的初始化 
    h[0].bre=0;
    h[0].che=0;
    h[0].sau=0;
    h[0].price=0;
    for(int i=0;i<=slen;++i)
    {
        if(s[i]=='B')
            h[0].bre++;
        if(s[i]=='C')
            h[0].che++;
        if(s[i]=='S')
            h[0].sau++;        
    }
    //cout<<h[0].bre<<" "<<h[0].che<<" "<<h[0].sau<<" "<<endl;检测初始化好了没QAQ 
    //材料的输入 
    scanf("%d%d%d%d%d%d",&nb,&ns,&nc,&pb,&ps,&pc);
    h[0].price=pb*h[0].bre+ps*h[0].sau+pc*h[0].che;
    cin>>mon;

//------------材料的处理 
    long long l=0,r=1e15,mid=(l+r)/2;
    
    while(l<r)
    {
        if(money(mid)<=mon)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
     } 
    if(money(mid)>mon)
        cout<<mid-1<<endl;
    else
        cout<<mid<<endl;
    return 0;
}

 

posted @ 2019-07-15 19:31  鹤花之歌  阅读(154)  评论(0编辑  收藏  举报