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>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;

typedef long long ll;
ll C, hr, wr, hb, wb;
int main()
{
	//freopen("t.txt", "r", stdin);
	while (cin >> C >> hr >> hb >> wr >> wb)
	{
		ll ans = 0;
		for (ll i = 0; i < 100000; i++)
		{
			if (i*wr <= C)
				ans = max(ans, i*hr + (C - wr*i) / wb*hb);
			if (i*wb <= C)
				ans = max(ans, i*hb + (C - wb*i) / wr*hr);
		}
		cout << ans << endl;
	}
	return 0;
}
时间: 2024-08-04 05:01:14

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/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

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跳到的