ZeptoLab Code Rush 2015 C. Om Nom and Candies [ 数学 ]
1 second
256 megabytes
standard input
standard output
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs Wr grams and each blue candy weighs Wb grams. Eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).
Print a single integer — the maximum number of joy units that Om Nom can get.
10 3 5 2 3
16
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
哎,做过一次,知道了最大公约数化简,最后枚举的时候忘了用大的枚举。。。
10596551 | 2015-04-05 05:09:39 | njczy2010 | C - Om Nom and Candies | GNU C++ | Accepted | 31 ms | 0 KB |
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <map> #define ll long long
int const N = ;
int const M = ;
int const INF = 0x3f3f3f3f;
ll const mod = ; using namespace std; ll c,hr,hb,wr,wb;
ll g;
ll ans;
ll ma;
ll lcm; ll gcd(ll a,ll b)
{
if(b==)
return a;
return gcd(b,a%b);
} void ini()
{
g=gcd(wr,wb);
if(wr<wb){
swap(wr,wb);
swap(hr,hb);
}
lcm=wr*wb/g;
ans=;
ma=;
} void solve()
{
if(c%lcm==){
ans=max(c/wr*hr,c/wb*hb);
return;
}
ll shang=c/lcm;
if(shang>=){
c-=lcm*(shang-);
ans=(shang-)*(max(lcm/wr*hr,lcm/wb*hb));
}
ll i;
for(i=;i*wr<=c;i++){
ma=max(ma,i*hr+(c-i*wr)/wb*hb);
}
ans+=ma;
} void out()
{
printf("%I64d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
//scanf("%d",&T);
//for(int cnt=1;cnt<=T;cnt++)
//while(T--)
while(scanf("%I64d%I64d%I64d%I64d%I64d",&c,&hr,&hb,&wr,&wb)!=EOF)
{
ini();
solve();
out();
}
}
ZeptoLab Code Rush 2015 C. Om Nom and Candies [ 数学 ]的更多相关文章
- ZeptoLab Code Rush 2015 C. Om Nom and Candies 暴力
C. Om Nom and Candies Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526 ...
- Codeforces - ZeptoLab Code Rush 2015 - D. Om Nom and Necklace:字符串
D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
B. Om Nom and Dark Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who l ...
- Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)
题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...
- CodeForces ZeptoLab Code Rush 2015
拖了好久的题解,想想还是补一下吧. A. King of Thieves 直接枚举起点和5个点之间的间距,进行判断即可. #include <bits/stdc++.h> using na ...
- Zepto Code Rush 2014 B - Om Nom and Spiders
注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...
- CF Zepto Code Rush 2014 B. Om Nom and Spiders
Om Nom and Spiders time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- ZeptoLab Code Rush 2015 A. King of Thieves 暴力
A. King of Thieves Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526/pr ...
随机推荐
- CentOS下JRE环境变量配置
很多时候,我们需要在CentOS上部署tomcat,从而搭建web服务器,然JDK/JRE环境是前提,这里就记录一下,在后面的时候直接使用. 下载jre-7u80-linux-x64.tar.gz,并 ...
- Centos 6 安装python2.7.6
centos 是自带python的.但是版本稍微旧一些.搞python开发,肯定要用新一点的稳定版.所以,要升级一下python. 先去python主站下载python的源码包:Python-2.7. ...
- Redis学习笔记(二)字符串进阶
1.增减操作 字符串可以储存字节串.整数.浮点数三种类型的值,如果值无法被解释为十进制的整数或浮点数,那么对此值进行增减操作会返回错误,如果对一个不存在的或者保存了空串的键进行增减操作,Redis将当 ...
- android 图片叠加效果——两种方法的简介与内容 ,带解决Immutable bitmap passed to Canvas constructor错误
第一种是通过canvas画出来的效果: public void first(View v) { // 防止出现Immutable bitmap passed to Canvas constructor ...
- 介绍三款大前端UI框架
一.蚂蚁金服团队推出的基于React antd (全名:ant.design) 友情跳链:https://ant.design/index-cn:使用antd模板:https://pro.ant.de ...
- uva10366 Faucet Flow
每次找到两边离中心最高的板,如果等,再找外围的最高版...画图便于理解两边先找到距离(-1,1)最近的最大值L和R,因为可能存在多个最高的挡板.接着比较两个L和R的大小,相等的话分别分析两边,取最小值 ...
- javaweb系列-关于HttpSessionListener的sessionDestroyed什么时候触发
根据书本写了下面这个监听器,然后开始调试,打开一个浏览器来访问该网页,可以正常触发sessionCreated,然后关闭浏览器,发现没有触发sessionDestroyed,然后我怀疑是不是这个监听器 ...
- selective_search_rcnn.m中代码
im = imresize(im, [NaN im_width]):把图像转换为宽度为im_width,自动计算列数
- Python虚拟环境 之 virtualenv 与 virtualenvwrapper
在开发Python应用程序的时候,比如系统安装的Python3只有一个版本:3.6.所有第三方的包都会被 pip 安装到Python3的 site-packages 目录下. 如果我们要 ...
- django 127.0.0.1 将您重定向的次数过多
"GET /?next=/%3Fnext%3D/%253Fnext%253D/ HTTP/1.1" 302 0 solution reference from django.con ...