一个乱七八糟的故事背景,可以练练英语阅读。

大概的意思是Polycarpus喜欢汉堡,现在他有你ns片香肠片,nb面包,nc块起司,有r卢布,每种东西都有价格,如果不够他可以去商店买(商店里面各种东西都是无限多的),制作汉堡需要多少各种东西都已经用字符串给出了,求他最多可以制作出多少汉堡。

简单二分,主意的是二分的上界,可能会超过10^12,就因为这个WA了两次。

#include <stdio.h>
#include <string.h>
#define maxn 2000000000000
#define ll long long
#include <iostream> using namespace std; int cntb, cnts, cntc;
int nb, ns, nc;
int pb, ps, pc;
ll r;
char str[105]; ll cal(ll x)
{
ll sum = 0;
if (x*cntb - nb > 0)
sum += (x*cntb - nb) * pb;
if (x*cntc - nc > 0)
sum += (x*cntc - nc) * pc;
if (x*cnts - ns > 0)
sum += (x*cnts - ns) * ps;
return sum;
} ll binarysearch(ll l, ll r, ll x)
{
//cout << l << " " << r << " " << x << endl;
if (l == r)
{
while (cal(l) > x)
l--;
return l;
} ll mid = (l+r)>>1;
if (cal(mid) > x)
return binarysearch(l, mid, x);
else
return binarysearch(mid+1, r, x);
} int main()
{
while (scanf("%s", str) != EOF)
{
int len = strlen(str);
cntb = 0, cnts = 0, cntc = 0;
for (int i = 0; i < len; i++)
{
if (str[i] == 'B')
cntb++;
else if (str[i] == 'S')
cnts++;
else if (str[i] == 'C')
cntc++;
}
scanf("%d %d %d", &nb, &ns, &nc);
scanf("%d %d %d", &pb, &ps, &pc);
cin >> r;
cout << binarysearch(0, maxn, (ll)r) << endl;
}
return 0;
}

最新文章

  1. Mongoose Schemas定义中timestamps选项的妙用
  2. Windows Live Writer 的昨日荣光
  3. eAccelerator、memcached、xcache、APC 等四个加速扩展的区别
  4. HD1814Peaceful Commission(模板题)
  5. 【BZOJ-3172】单词 AC自动机
  6. Codeforces Round #250 (Div. 2)A(英语学习)
  7. systemtap 列出所有linux 内核模块与相关函数0
  8. 练习题之ThreadLocal
  9. OMCS的语音视频带宽占用
  10. 配置Nginx 1.8支持PHP 5.6
  11. build setting
  12. 关于C#时间格式化中的&ldquo;f&rdquo;
  13. ASP.NET中ListBox控件的使用
  14. Http Post与Get等
  15. 架构师之路--应用架构的选型和dubbo
  16. 如何下载西门子产品CAD、3D和EPLAN文件
  17. React hooks实践
  18. 微信开发】【Asp.net MVC】-- 微信分享功能
  19. spring cloud开发、部署注意
  20. Codeforces 394D Physical Education and Buns 胡搞

热门文章

  1. prometheus-operator监控Kubernetes
  2. 面试超火题 This的问题!!!
  3. 统一资源定位符URL
  4. Apicloud 接入海康摄像头
  5. Centos7下安装Mysql8.0
  6. java虚拟机-JDK8-废弃永久代(PermGen)迎来元空间(Metaspace)
  7. C++学习书籍推荐《Exceptional C++》下载
  8. 剑指offer第二版-总结:二叉树的遍历
  9. 最大公约数GCD学习笔记
  10. 常用的re模块的正则匹配的表达式