题意:

T,A,B。T是上限。A和B可以随意吃但是不能超过T。有一次将吃的东西/2的机会。然后可以继续吃,不能超过T。问最多可以吃多少。

=>我们先处理不能/2可以吃到哪些。然后弄个双指针扫一扫就可以了TAT

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=5e6+5;
const int inf=0x7f7f7f7f;
bool dp[nmax];int a[nmax];
int main(){
int T=read(),A=read(),B=read();
dp[0]=1;
rep(i,A,T) dp[i]|=dp[i-A];
rep(i,B,T) dp[i]|=dp[i-B];
rep(i,0,T) if(dp[i]) dp[i/2]=1;
rep(i,0,T) if(dp[i]) a[++a[0]]=i;
int ans=0,l=1,r=a[0];
while(l<=r){
while(l<r&&a[r]+a[l]>T) --r;
if(l==r) break;
ans=max(ans,a[l]+a[r]);++l;
}
printf("%d\n",ans);return 0;
}

  

4393: [Usaco2015 Dec]Fruit Feast

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 160  Solved: 99
[Submit][Status][Discuss]

Description

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!

奶牛Bessie潜入了农夫约翰的家,她发现这里有无穷无尽的柠檬派和橘子派。

Bessie的饱胀值一开始是0,且上限是T,每个柠檬派可以提供A点饱胀值,每个橘子派可以提供B点饱胀值。

Bessie可以不断地吃东西,如果她的饱胀值没有超出T的话。同时,Bessie有一次喝水的机会,喝完后,她的饱胀值将减少一半(往下取整)。

请计算出Bessie的饱胀值最多可以达到多少。

Input

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

Output

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

Sample Input

8 5 6

Sample Output

8

HINT

 

Source

bzoj4393: [Usaco2015 Dec]Fruit Feast的更多相关文章

  1. BZOJ 4393: [Usaco2015 Dec]Fruit Feast

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

  2. BZOJ 4390: [Usaco2015 dec]Max Flow

    4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submi ...

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

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

  4. Fruit Feast

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

  5. 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)

    [BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...

  6. bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和

    4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec  Memory Limit: 128 MB Description Farmer John ...

  7. BZOJ5142: [Usaco2017 Dec]Haybale Feast(双指针&set)(可线段树优化)

    5142: [Usaco2017 Dec]Haybale Feast Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 182  Solved: 131[ ...

  8. [Usaco2015 dec]Max Flow 树上差分

    [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 353  Solved: 236[Submit][Sta ...

  9. Fruit Feast(暴力)(动态规划)

    Fruit Feast 时间限制: 1 Sec  内存限制: 64 MB提交: 64  解决: 18[提交][状态][讨论版] 题目描述 Bessie has broken into Farmer J ...

随机推荐

  1. webpack@3.6.0(4) -- 配置模块化开发

    本篇内容 watch 版权插件 hash.chunkhash.contenthash的区别 watch 修改文件时自动打包 webpack --watch //webpack.config.js,与d ...

  2. Hibernate单表映射学习笔记之一——hibernalnate开发环境配置

    1.什么是ORM? Object/Relationship Mapping:对象/关系映射 2.写SQL语句不好之处: (1)不同数据库使用的SQL语法不同(PL/SQL.T/SQL) (2)同样的功 ...

  3. 洛谷P4332 [SHOI2014]三叉神经树(LCT)

    传送门 FlashHu大佬太强啦%%% 首先,我们可以根据每一个点的权值为$1$的儿子的个数把每个点记为$0~3$,表示这一个点的点权 先考虑一下暴力的过程,假设从$0$变为$1$,先更改一个叶子结点 ...

  4. java整理(三)

    1.继承性:继承已有的功能.使用extends关键字.class  子类   extends  父类{} 子类又被称为派生类,父类又被称为超类. 继承的限制: 1.java中,不允许多重继承,即一个子 ...

  5. 如何从git上clone一个项目

    今天想从自己的git上down下来代码,补充一些新的学习demo,不过因为平时工作中不适用git管理代码,所以,有些命令行忘记了.现在,通过这种方式再加深一遍印象吧. 那我就假设已经安装好了git了. ...

  6. 解读人:李思奇,Development of a sensitive, scalable method for spatial, cell-type-resolved proteomics of the human brain. (一种用于研究人类大脑基于空间或细胞类型的蛋白质组学的灵敏方法)

    发表时间:(2019年4月) 一. 概述: 本文报道了一种可研究人类大脑组织中特定神经细胞的蛋白质组学的方法.作者通过激光捕获显微切割技术(LCM)从逝者大脑中分离出目的神经元细胞,接着尝试了一系列不 ...

  7. luoguP4921 情侣?给我烧了!

    luogu 考虑对于\(n\)对情侣,恰好\(k\)对是和谐的方案数是 \[ ans[n][k]=\binom{n}{k}A^k_n2^kg(n-k) \] \(g(n)\)为全部\(n\)对情侣不和 ...

  8. CF C. Maximal Intersection(贪心 || STL)

    题意 给你N个线段(一条直线上),问删去一个之后,最长公共长度 : 分析:首先我们得先知道n条线段公共的线段一定是(LMAX,RMIN) ,那我们可以先排序,然后枚举删除边: #include< ...

  9. java动态线程池LinkedBlockingQueue和SynchronousQueue比较

    import java.util.concurrent.Callable; public class MyCallable implements Callable<String> { pr ...

  10. Java匹马行天下之JavaWeb核心技术——JSP

    JSP动态网页技术 一.JavaWeb简介 一.什么是JavaWeb? JavaWeb是用Java技术来解决相关web互联网领域的技术总称. 需要在特定的web服务器上运行,分为web服务器和web客 ...