Fruit Feast

时间限制: 1 Sec  内存限制: 64 MB
提交: 64  解决: 18
[提交][状态][讨论版]

题目描述

Bessie
has broken into Farmer John's house again! She has discovered a pile of
lemons and a pile of oranges in the kitchen (effectively an unlimited
number of each), and she is determined to eat as much as possible.

Bessie has a maximum fullness of T(1≤T≤5,000,000). Eating an orange increases her fullness by A, and eating a lemon increases her fullness by B (1≤A,B≤T).
Additionally, if she wants, Bessie can drink water at most one time,
which will instantly decrease her fullness by half (and will round
down).

Help Bessie determine the maximum fullness she can achieve!

输入

The first (and only) line has three integers T, A, and B.

输出

 A single integer, representing the maximum fullness Bessie can achieve.

样例输入

8 5 6

样例输出

8
【分析】在此提供两种做法,一种暴力,一种动态规划。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=;
const int M=;
ll sum=;
int n,m;
int vis[N];
int maxn=;
struct man
{
int num,use;
};
int main()
{
int a,b;
memset(vis,,sizeof(vis));
scanf("%d%d%d",&n,&a,&b);
queue<man>q;
man A;A.num=a;A.use=;
man B;B.num=b;B.use=;
q.push(A);q.push(B);
vis[a]=;vis[b]=;
while(!q.empty()){
man t=q.front();
q.pop();
if(t.num+a>n)maxn=max(maxn,t.num);
if(t.num+a<=n&&vis[t.num+a]==){
vis[t.num+a]=;
man k;k.num=t.num+a;k.use=t.use;
q.push(k);
}
if(t.num+b>n)maxn=max(maxn,t.num);
if(t.num+b<=n&&vis[t.num+b]==){
vis[t.num+b]=;
man k;k.num=t.num+b;k.use=t.use;
q.push(k);
}
if(t.use==&&vis[t.num/]==){
vis[t.num/]=;
man k;k.num=t.num/;k.use=;
q.push(k);
}
}
printf("%d\n",maxn);
return ;
}

暴力

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=;
const int M=;
ll sum=;
int n,m;
int vis[N];
int maxn=;
int dp[N];
int main()
{
int a,b;
scanf("%d%d%d",&n,&a,&b);
dp[]=;
for(int i=a;i<=n;i++)dp[i]|=dp[i-a];
for(int i=b;i<=n;i++)dp[i]|=dp[i-b];
for(int i=;i<=n;i++)dp[i/]|=dp[i];
for(int i=a;i<=n;i++)dp[i]|=dp[i-a];
for(int i=b;i<=n;i++)dp[i]|=dp[i-b];
for(a =n;dp[a]==;a--);
cout<<a<<endl;
return ;
}

动态规划

Fruit Feast(暴力)(动态规划)的更多相关文章

  1. USACO 2015 December Contest, Gold Problem 2. Fruit Feast

    Problem 2. Fruit Feast 很简单的智商题(因为碰巧脑出来了所以简单一,一 原题: Bessie has broken into Farmer John's house again! ...

  2. Fruit Feast

    Fruit Feast 题目描述 Bessie has broken into Farmer John's house again! She has discovered a pile of lemo ...

  3. bzoj4393: [Usaco2015 Dec]Fruit Feast

    题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫 ...

  4. P4817 [USACO15DEC]Fruit Feast 水果盛宴

    P4817 [USACO15DEC]Fruit Feast 水果盛宴 现在Bessie的饱食度为 00 ,她每吃一个橙子,饱食度就会增加 AA :每吃一个柠檬,饱食度就会增加 BB .Bessie还有 ...

  5. BZOJ 4393: [Usaco2015 Dec]Fruit Feast

    DP #include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf(&q ...

  6. P4817 Fruit Feast G

    最开始拿到这道题的时候,题目中其实只规定了两种水果的饱食度,可以理解成价值或是重量,在不超过T的情况求最大值.第一眼看过去感觉就是装箱问题(背包),只不过这道题用的是完全背包,但是考虑到喝水的情况,做 ...

  7. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. dp式子100个……

    1.        资源问题1-----机器分配问题F[I,j]:=max(f[i-1,k]+w[i,j-k]) 2.        资源问题2------01背包问题F[I,j]:=max(f[i- ...

随机推荐

  1. BZOJ3456 城市规划 【多项式求逆】

    题目链接 BZOJ3456 题解 之前我们用分治\(ntt\)在\(O(nlog^2n)\)的复杂度下做了这题,今天我们使用多项式求逆 设\(f_n\)表示\(n\)个点带标号无向连通图数 设\(g_ ...

  2. BZOJ1044 [HAOI2008]木棍分割 【二分+Dp】

    1044: [HAOI2008]木棍分割 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 4281  Solved: 1644 [Submit][St ...

  3. CF763C Timofey and Remoduling

    题目戳这里. 这道题目纯粹是考思维. 若\(2N \le M\),由于答案肯定是\(s,s+d,\dots,s+(N-1)d\),我们任意枚举两个数\(a,b\),不妨设\(b\)在数列中出现在\(a ...

  4. 这次OpenSSL HeartBleed漏洞是怎么一回事呢?

    “心脏出血”(Heartbleed)被称为互联网史上最严重的安全漏洞之一,波及了大量常用网站.服务,包括很多人每天都在用的 Gmail 等等,可能导致用户的密码.信用卡轻易泄露.但是我们可能对它还不是 ...

  5. 如何用Ajax传一个数组数据

    PHP接收多个同名复选框信息不像ASP那样自动转换成为数组,这给使用带来了一定不便.但是还是有解决办法的,就是利用javascript做一下预处 理.多个同名复选框在javascript中还是以数组的 ...

  6. IE浏览器被固定启动时访问某网页的处理方法

    一.问题的提出 有些windows的GHOST系统在镜像成使用系统后或者正规安装的windows系统在安装金山毒霸.360杀毒软件后,IE浏览器一打开就自动打开某个指定的网站. 二.问题的分析 1.I ...

  7. Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph

    D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...

  8. xiaoluo同志Linux学习之CentOS6.4

    小罗同志写的不错,弄个列表过来啊   Linux学习之CentOS(三十六)--FTP服务原理及vsfptd的安装.配置 xiaoluo501395377 2013-06-09 01:04 阅读:56 ...

  9. php 计算两个日期的间隔天数

    使用php内部自带函数实现 1.使用DateTime::diff 实现计算 参考阅读>>PHP DateTime::diff() 上代码: <?php $start = " ...

  10. leetcode-501. Find Mode in Binary Search Tree

    Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred ...