• 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/problem/C

    Description

    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 Input

    10 3 5 2 3

    Sample Output

    16

    HINT

    题意

    只有两个物品的多重背包问题

    题解:

    啊, 正解实在不会,只能乱搞
    那就正向枚举1000W个A物品,再逆向枚举1000W个A物品
    当然这样子乱搞,我也不保证正确性,不过还是A了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    //const int inf=0x7fffffff;   //无限大
    const int inf=0x3f3f3f3f;
    /*
    
    int buf[10];
    inline void write(int i) {
      int p = 0;if(i == 0) p++;
      else while(i) {buf[p++] = i % 10;i /= 10;}
      for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
      printf("
    ");
    }
    */
    //**************************************************************************************
    
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    
    int main()
    {
        ll c,hr,hb,wr,wb;
        ll ans=0;
        cin>>c>>hr>>hb>>wr>>wb;
        if(wr==wb)
        {
            cout<<c/wr*max(hr,hb)<<endl;
            return 0;
        }
        if(wr<wb)
        {
            swap(wr,wb);
            swap(hr,hb);
        }
        int time=0;
        for(int i=c/wr;i>=0;i--)
        {
            time++;
            ll sum=i*hr+(c-wr*i)/wb*hb;
            ans=max(sum,ans);
            if(time>10000000)
                break;
        }
        //cout<<ans<<endl;
            swap(wr,wb);
            swap(hr,hb);
        time=0;
        for(int i=c/wr;i>=0;i--)
        {
            time++;
            ll sum=i*hr+(c-wr*i)/wb*hb;
            ans=max(sum,ans);
            if(time>10000000)
                break;
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    vim替换
    vim 常用快捷键 二
    vim撤销
    让你提升命令行效率的 Bash 快捷键
    快速正确的安装 Ruby, Rails 运行环境
    STL的常用算法
    Ubuntu下Postfix邮件服务器安装及基本的设置
    vim 参考手册
    指针 多维数组 数组指针 指针数组
    数学小抄
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4393499.html
Copyright © 2020-2023  润新知