bzoj4393: [Usaco2015 Dec]Fruit Feast

题意:php

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

=>咱们先处理不能/2能够吃到哪些。而后弄个双指针扫一扫就能够了TATui

#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!spa

 

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

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

Bessie能够不断地吃东西,若是她的饱胀值没有超出T的话。同时,Bessie有一次喝水的机会,喝完后,她的饱胀值将减小一半(往下取整)。three

请计算出Bessie的饱胀值最多能够达到多少。ip

 

Input

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

Output

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

Sample Input

8 5 6

Sample Output

8

HINT

 

Source

相关文章
相关标签/搜索