传送门

C. Om Nom and Candies
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).

Output

Print a single integer — the maximum number of joy units that Om Nom can get.

Sample test(s)
Input
10 3 5 2 3
Output
16
Note

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 [ 数学 ]的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)

    题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...

  6. CodeForces ZeptoLab Code Rush 2015

    拖了好久的题解,想想还是补一下吧. A. King of Thieves 直接枚举起点和5个点之间的间距,进行判断即可. #include <bits/stdc++.h> using na ...

  7. Zepto Code Rush 2014 B - Om Nom and Spiders

    注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. enum,sizeof,typedef

    枚举类型的使用方法 enum是C语言中的一种自定义类型 enum值可以根据需要自定义整形值 第一个定义的enum值默认为0 默认情况下的enum值是在前一个定义值得基础上加1 enum类型的变量只能去 ...

  2. Python3简明教程(一)—— 开始Python之旅

    第一个Python程序 作为我们第一个Python程序——打印"Hello  World!". 在终端输入Python3进入交互界面: 输入print("Hello  W ...

  3. params.row[params.column.key] vue h函数 当前单元格 h函数 div 属性 值或数组 render

    params.row[params.column.key] vue h函数 当前单元格 h函数 div 属性 值或数组 render

  4. C-基础:C语言为什么不做数组下标越界检查

    //这段代码运行有可能不报错.]; ;i<;i++) { a[i]=i; } 1.为了提高运行效率,不检查数组下表越界,程序就可以跑得快.因为C语言并不是一个快速开发语言,它要求开发人员保证所有 ...

  5. 二分+贪心 || CodeForces 551C GukiZ hates Boxes

    N堆石头排成一列,每堆有Ai个石子.有M个学生来将所有石头搬走.一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间. *解法:二分答案x( ...

  6. 批处理 更新 svn git hg

    @echo off Setlocal enabledelayedexpansion ::CODER BY Administrator POWERD BY iBAT 1.6 ::设置svn默认安装位置以 ...

  7. spring注解开发-IOC

    1. @Configuration, @Bean @Configuration该注解就是用来告诉spring这是配置类 @Bean该注解是用来注册一个bean.类型是返回值的类型,ID默认是用方法名作 ...

  8. poj2368 Buttons

    题目描述 题解: 非常简单的巴什博弈问题. 简单来说保证$L+1$是$K$的因数即可. 决策是,先手取$x$个,后手就取$L+1-x$个. 那个$L>=2$真的很坑. 代码: #include& ...

  9. Spring Boot 默认配置无法访问静态资源

    问题:将资源放在resources/static目录下,Spring boot不能加载 解决:在启动文件中,添加如下红字部分. @SpringBootApplication @Configuratio ...

  10. u-boot-2012.04.01移植笔记——支持NAND启动

    1.加入nand读写函数文件: 对于nand的读写我们需要特定的函数,之前写最小bootloader的时候曾写过nand.c文件,我们需要用到它.为了避免混淆,我们先将其改名为init.c,然后拷贝到 ...