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. 【题解】WC2008游览计划

    写的第一道斯坦纳树的题目.斯坦纳树在信息学中的应用一般为:在\(n\)个点之间给定\(k\)条边并相应的边权,求在保证给定\(m\)个点联通的条件下的最小边权和.解决此类问题的方法即为SPFA + 状 ...

  2. HttpClientUntils工具类的使用测试及注意事项(包括我改进的工具类和Controller端的注意事项【附 Json 工具类】)

    HttpClient工具类(我改过): package com.taotao.httpclient; import java.io.IOException; import java.net.URI; ...

  3. Eclipse中的Web项目自动部署到Tomcat的webapp目录下

    Eclipse中的Web项目自动部署到Tomcat   原因 很长时间没用Eclipse了,近期由于又要用它做个简单的JSP项目,又要重新学习了,虽然熟悉的很快,但记忆总是很模糊,偶尔犯错,以前很少写 ...

  4. 转:Nginx国人开发缩略图模块(ngx_image_thumb)

    ngx_image_thumb是nginx中用来生成缩略图的模块,生存缩略图的方法很多,之前也写过一篇 <nginx生成缩略图配置>,在github上发现国人开发的一款模块,作者的文档写的 ...

  5. jspersonft有关Table数据绑定(一)

    一:前言 在公司来就学着做报表,觉得这个报表学着还是很有意义的.jspersonft我在网上搜了一些有关的资料但是不是很多,现在就是学一点就记载一点.好记性不如烂笔头嘛! 二:在jspersonft定 ...

  6. rpmdb open failed解决方案

    1.前提条件:安装软件包的时候,被我手动终止了(可能出错原因)[root@dhcp yum.repos.d]# yum clean allrpmdb: Thread/process 4541/1406 ...

  7. 洛谷 PT2 First Step (ファーストステップ)

    题目背景 知らないことばかりなにもかもが(どうしたらいいの?) 一切的一切 尽是充满了未知数(该如何是好) それでも期待で足が軽いよ(ジャンプだ!) 但我仍因满怀期待而步伐轻盈(起跳吧!) 温度差なん ...

  8. 关于dlib人脸对比,人脸识别

    人脸检测 人脸特征点提取 人脸对比,等于两张人脸对比,识别 封装的所有识别函数,直接看下面调用就好了. # coding:utf-8 ''' 本本次封装,我主要是做两张人脸对比. 就只人脸识别部分,简 ...

  9. Linux虚拟地址空间布局以及进程栈和线程栈总结【转】

    转自:http://www.cnblogs.com/xzzzh/p/6596982.html 原文链接:http://blog.csdn.net/freeelinux/article/details/ ...

  10. JMeter之定时器的作用域

    定时器的作用域 1.定时器是在每个sampler(采样器)之前执行的,而不是之后(无论定时器位置在sampler之前还是下面): 2.当执行一个sampler之前时,所有当前作用域内的定时器都会被执行 ...