一道二分——CodeForces - 371C

题目链接

题目代码

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long LL;
const LL inf=2000000000000;
char str[100];
int b,s,c,nb,ns,nc,pb,ps,pc;
LL r;
bool check(LL p){
    LL bb=(p*b-nb)*pb,ss=(p*s-ns)*ps,cc=(p*c-nc)*pc;
    if(bb<0)bb=0;
    if(ss<0)ss=0;
    if(cc<0)cc=0;
    LL cost=bb+ss+cc;
    if(r>=cost)return true;
    else return false;
}
int main(){
    b=s=c=0;
    scanf("%s",&str);
    for(int i=0;i<strlen(str);i++){
        if(str[i]=='B')b++;
        else if(str[i]=='S')s++;
        else if(str[i]=='C')c++;
    }
    scanf("%d%d%d",&nb,&ns,&nc);
    scanf("%d%d%d",&pb,&ps,&pc);
    scanf("%I64d",&r);
    LL low=1,high=inf;
    while(low<high){
        LL mid=(low+high)/2;
        if(check(mid))low=mid+1;
        else high=mid;
    }
    printf("%I64d\n",low-1);
    return 0;
}

 

posted @ 2019-08-12 20:21  helman78  阅读(137)  评论(0编辑  收藏  举报