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
Output
Sample Input
10 3 5 2 3
Sample Output
HINT
题意
只有两个物品的多重背包问题
题解:
啊, 正解实在不会,只能乱搞
代码:
//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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} int main()
{
ll c,hr,hb,wr,wb;
ll ans=;
cin>>c>>hr>>hb>>wr>>wb;
if(wr==wb)
{
cout<<c/wr*max(hr,hb)<<endl;
return ;
}
if(wr<wb)
{
swap(wr,wb);
swap(hr,hb);
}
int time=;
for(int i=c/wr;i>=;i--)
{
time++;
ll sum=i*hr+(c-wr*i)/wb*hb;
ans=max(sum,ans);
if(time>)
break;
}
//cout<<ans<<endl;
swap(wr,wb);
swap(hr,hb);
time=;
for(int i=c/wr;i>=;i--)
{
time++;
ll sum=i*hr+(c-wr*i)/wb*hb;
ans=max(sum,ans);
if(time>)
break;
}
cout<<ans<<endl;
}
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 per test 1 second memory limit per test 256 megabytes input sta ...
- 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 ...
随机推荐
- Linux 查看内存插槽数、最大容量的方法
查看内存插槽数: dmidecode|grep -P -A5 "Memory\s+Device"|grep Size|grep -v Range 查看最大容量: dmidecode ...
- 用Qemu模拟vexpress-a9 (一) --- 搭建Linux kernel调试环境【转】
转自:http://www.cnblogs.com/pengdonglin137/p/5023342.html#_label2 阅读目录(Content) 环境介绍: 下载Linux内核 安装arm的 ...
- ansible批量修改linux服务器密码的playbook
从网上找到批量修改Linux服务器root密码的playbook. 使用方法: 1.输入要修改的inventory组 2.按需要,在playbook中输入要修改的IP.新密码,如下: - hosts: ...
- No.12 selenium for python 截屏
一.selenium for python 提供的几种截图方法 从上至下,很容易理解 1.as_file 获取当前window的截图,参数filename则表示截图的路径以及名称 出现IOError时 ...
- C++ 虚函数及重载、重定义、重写
#include<iostream> usingnamespace std; class BASE { public: BASE()=default; BASE(int publicVal ...
- Centos之关机和重启命令
shutdown命令 shutdown [选项] 时间 -c:取消前一个关机命令 -h:关机 -r:重启 [root@localhost ~]# date 2017年 06月 21日 星期三 15:4 ...
- 涨姿势系列之——内核环境下花式获得CSRSS进程id
这个是翻别人的代码时看到的,所以叫涨姿势系列.作者写了一个获取CSRSS进程PID的函数,结果我看了好久才看懂是这么一个作用.先放上代码 HANDLE GetCsrPid() { HANDLE Pro ...
- 第六届CCF软件能力认证
1.数位之和 问题描述 给定一个十进制整数n,输出n的各位数字之和. 输入格式 输入一个整数n. 输出格式 输出一个整数,表示答案. 样例输入 20151220 样例输出 13 样例说明 201512 ...
- GridView练习题
package com.example.wang.myapplication; import android.os.Bundle; import android.support.v7.app.AppC ...
- HBase(四)HBase集群Shell操作
一.进入HBase命令行 在你安装的随意台服务器节点上,执行命令:hbase shell,会进入到你的 hbase shell 客 户端 [admin@node21 ~]$ hbase shell S ...