bzoj4393: [Usaco2015 Dec]Fruit Feast
题意:
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
Sample Output
HINT
Source
bzoj4393: [Usaco2015 Dec]Fruit Feast的更多相关文章
- BZOJ 4393: [Usaco2015 Dec]Fruit Feast
DP #include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf(&q ...
- BZOJ 4390: [Usaco2015 dec]Max Flow
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 177 Solved: 113[Submi ...
- USACO 2015 December Contest, Gold Problem 2. Fruit Feast
Problem 2. Fruit Feast 很简单的智商题(因为碰巧脑出来了所以简单一,一 原题: Bessie has broken into Farmer John's house again! ...
- Fruit Feast
Fruit Feast 题目描述 Bessie has broken into Farmer John's house again! She has discovered a pile of lemo ...
- 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)
[BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...
- bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和
4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec Memory Limit: 128 MB Description Farmer John ...
- BZOJ5142: [Usaco2017 Dec]Haybale Feast(双指针&set)(可线段树优化)
5142: [Usaco2017 Dec]Haybale Feast Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 182 Solved: 131[ ...
- [Usaco2015 dec]Max Flow 树上差分
[Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 353 Solved: 236[Submit][Sta ...
- Fruit Feast(暴力)(动态规划)
Fruit Feast 时间限制: 1 Sec 内存限制: 64 MB提交: 64 解决: 18[提交][状态][讨论版] 题目描述 Bessie has broken into Farmer J ...
随机推荐
- WebAPI学习及Swagger使用
本文用来保存自己学习WebAPI和Swagger使用过程中参考的文章,以及对WebAPI的初步了解. 1.RESTful风格 WebAPI只支持Http协议: 1.1.WebAPI与MVC的区别 Va ...
- 需要命名空间管理器或 XsltContext。此查询具有前缀、变量或用户定义的函数 及 多属性节点查询
第一个问题, 1. 首先需要引入命名空间, 2. 其次,在用xpath查找结点时,在selectNodes等方法中再次带入命名空间 如 XmlDocument doc = new XmlDocumen ...
- Java基础笔记(十五)——封装(续)static关键字
static 静态的,用static修饰的成员叫静态成员或类成员.类实例化的所有对象都会共用同一块静态空间.一个对象将值改变,其它对象的值也就随之改变了. 如:public static int pr ...
- PAT甲级——1094 The Largest Generation (树的遍历)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...
- POJ1031 Fence
题目来源:http://poj.org/problem?id=1031 题目大意: 有一个光源位于(0,0)处,一个多边形的围墙.围墙是“全黑”的,不透光也不反射光.距光源r处的光强度为I0=k/r, ...
- 平衡树合集(Treap,Splay,替罪羊,FHQ Treap)
今天翻了翻其他大佬的博客,发现自己有些...颓废... 有必要洗心革面,好好学习 序:正常的BST有可能退化,成为链,大大降低效率,所以有很多方法来保持左右size的平衡,本文将简单介绍Treap,S ...
- js——bootstrap框架
前端开发框架,移动优先,响应式布局开发. 网址:www.bootcss.com js有一个特性是阻塞加载,也就是说js文件如果没有加载完,不会进行后面的加载,所以例子中会把js文件写在body的最后一 ...
- Spring配置文件没有提示问题+log4j
1.Spring中引入schema约束,把约束文件引入Myeclipse (1)复制约束路径http://www.springframework.org/schema/beans/spring-bea ...
- ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall
题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K Feeling hungry, a cute hamster decides to o ...
- (转)linux 系统下虚拟用户的作用
原文:http://blog.csdn.net/luoshao20120430/article/details/16900653 http://blog.csdn.net/u01 ...