Can I use Chinese? <br/>
这个题是一道二分题目 <br/>
he question is a two-point question. <br/>
题意很简单,不需要解释了 <br/>
It is very simple, do not need to explain. <br/>
但是我一直没过样例,原因是我的变量类型搞错了 <br/>
But I haven‘t had the sample because my variables are wrong. <br/>
应该是`long long`,但是我写成了`int` <br/>
It should be `long long`, but I use the `int`. <br/>
下面是代码 <br/>
Next is my code. <br/>
#include <iostream> #include <cstring> #include <cstdio> using namespace std; int q[5]; // B C S int c[5]; int m[5]; char s[110]; int B,C,S; long long tot,ans; int check(long long n) { long long tmp=tot; if(n*c[1]>q[1]) tmp-=(n*c[1]-q[1])*m[1]; if(n*c[2]>q[2]) tmp-=(n*c[2]-q[2])*m[2]; if(n*c[3]>q[3]) tmp-=(n*c[3]-q[3])*m[3]; if(tmp>=0) return 1; else return 0; } int main() { cin>>s; for(int i=0;i<strlen(s);i++) { if(s[i]==‘B‘) c[1]++; if(s[i]==‘S‘) c[2]++; if(s[i]==‘C‘) c[3]++; } cin>>q[1]>>q[2]>>q[3]; cin>>m[1]>>m[2]>>m[3]; cin>>tot; int d=tot; long long l=1,r=2333333333333; long long mid; while(l<=r) { mid=(l+r)/2; if(check(mid)) l=mid+1,ans=mid; else r=mid-1; } cout<<ans; return 0; }
时间: 2024-10-09 22:42:16