Fruit Feast
Time limit: 1 Sec memory limit: up to MB
Submitted: 18 Resolution:
Submitted State [Discussion Version]
Title DescriptionBessie have 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 SH E is determined to eat as much as possible.
Bessie has a maximum fullness of T(1≤t≤5,000,000). Eating an orange increases she fullness by A, and Eating A lemon increases she fullness by B (1≤a,b≤t). Additionally, if she wants, Bessie can drink water at the most one time, which would instantly decrease her fullness by half (a ND would round down).
Help Bessie determine the maximum fullness she can achieve!
InputThe first (and only) line has three integers T, A, and B.
OutputA single Integer, representing the maximum fullness Bessie can achieve.
Sample input
8 5 6
Sample output
8
"Analytics" provides two approaches, a kind of violence, a dynamic programming.
#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>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll;Const intn=5000005;Const intm=15005; ll Sum=1;intn,m;intVis[n];intmaxn=0;structman{intNum,use;};intMain () {intb; memset (Vis,0,sizeof(VIS)); scanf ("%d%d%d",&n,&a,&b); Queue<man>Q; Man A; A.num=a; A.use=0; Man B; B.num=b; B.use=0; Q.push (A); Q.push (B); Vis[a]=1; vis[b]=1; 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]==0) {Vis[t.num+a]=1; Mans 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]==0) {Vis[t.num+b]=1; Mans K;k.num=t.num+b;k.use=T.use; Q.push (k); } if(t.use==0&&vis[t.num/2]==0) {Vis[t.num/2]=1; Mans K;k.num=t.num/2; k.use=1; Q.push (k); }} printf ("%d\n", MAXN); return 0;}violence
#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>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll;Const intn=5000005;Const intm=15005; ll Sum=1;intn,m;intVis[n];intmaxn=0;intDp[n];intMain () {intb; scanf ("%d%d%d",&n,&a,&b); dp[0]=1; for(inti=a;i<=n;i++) dp[i]|=dp[i-a]; for(inti=b;i<=n;i++) dp[i]|=dp[i-b]; for(intI=0; i<=n;i++) dp[i/2]|=Dp[i]; for(inti=a;i<=n;i++) dp[i]|=dp[i-a]; for(inti=b;i<=n;i++) dp[i]|=dp[i-b]; for(A =n;dp[a]==0; a--); cout<<a<<Endl; return 0;}Dynamic Planning
Fruit Feast (violence) (Dynamic planning)