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("\n");
}
*/
//**************************************************************************************

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;
}
时间: 2024-08-27 15:00:07

ZeptoLab Code Rush 2015 C. Om Nom and Candies 暴力的相关文章

ZeptoLab Code Rush 2015 C. Om Nom and Candies

1.题目描述:点击打开链接 2.解题思路:本题是无限背包问题,根据重量的约束关系,直接暴力搜索. 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> #include<vector> #include<stack> #incl

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/526/problem/B Description Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living a

ZeptoLab Code Rush 2015 B. Om Nom and Dark Park

1.题目描述:点击打开链接 2.解题思路:比赛时候这道题没有做出来,第二天早晨补题时才发现就是简单的DFS应用.题目要求出最少需要增加几盏路灯.假设我们已经知道了root的左子结点一共有suml盏路灯,右子结点一共有sumr盏路灯,那么比较一下d[lson(root)]+suml和d[rson(root)]+sumr的大小即可.此时需要增加的路灯数量就是两者差的绝对值.同时返回较大的数即得到root的总路灯数量. 3.代码: #define _CRT_SECURE_NO_WARNINGS #in

Codeforces ZeptoLab Code Rush 2015

比赛链接:http://codeforces.com/contest/526/ A. King of Thieves time limit per test:1 second memory limit per test:256 megabytes In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves&quo

【codeforces ZeptoLab Code Rush 2015】ABCD题解

A. King of Thieves time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves&quo

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/problem/A Description In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" y

ZeptoLab Code Rush 2015

A 题意:给出一串由.*组成的字符串,如果有等间距的五个及五个以上的*存在,则输出yes 直接枚举就可以了 看题一定要仔细啊,做的时候看成必须有五个等间距的".*"才可以跳跃= = 然后就这样写居然过了预测= =后来果然被hack了 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6

ZeptoLab Code Rush 2015 A. King of Thieves

题目大意: 就是说,对于一个起点,使得从这个起点开始,每次间隔相同的格子后,所经过的地方都是‘*’ 解题思路: 直接暴力,枚举起点+枚举公差 代码: 1 # include<cstdio> 2 # include<iostream> 3 4 using namespace std; 5 6 # define MAX 123 7 8 char s[MAX]; 9 int a[MAX]; 10 11 int main(void) 12 { 13 int n; 14 scanf(&quo

【codeforces】ZeptoLab Code Rush 2015 E 跳跃表?

题意就是给n个数,围成一圈,就是1和n是相邻的,然后给一个数b,总和不超过b的一段连续的数可以组成一组,问最少可以将n个数分成几组. 可以将n个数后面再接n个数,就变成n+n个数,然后以每个数为开头的组最远能到哪也是很容易求的,O(n)维护个指针可以处理.把远的位置视为跳一步能到的吧,这样问题就转化为1到n中的第i个数至少到第n+i个数要跳多少次.这个如果是一般图的话,就是类似树上求k步的祖先在哪,可以用倍增法,n*log(n).但是这题图比较特殊,i<j的话,i跳到的下一点位置不会超过j跳到的