C. Om Nom and Candies
Wireless Oversized backpack problem
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <stack> One#include <queue> A#include <sstream> -#include <iomanip> - using namespacestd; thetypedefLong LongLL; - Const intinf=0x4fffffff; - Const intexp=1e-5; - Const intms= A; + ConstLL size= +; - + intMain () A { at LL C,HR,HB,WR,WB; -Cin>>c>>hr>>hb>>wr>>WB; - if(wb>WR) - { - swap (WB,WR); - swap (HB,HR); in } - to if(wr>size)//cleverly controls complexity at 10e6 + { -LL ans=0LL; the for(LL r=0; r*wr<=c;r++) * { $LL b= (C-R*WR)/WB;Panax NotoginsengLL cur=r*hr+b*HB; - if(cur>ans) theans=cur; + } Acout<<ans<<Endl; the return 0; + } -LL ans=0; $LL H_big=max (wb*hr,wr*HB); $ for(LL r=0; r<wb;r++)//if R>=WB, can form a common multiple weight of big - { - for(LL b=0; b<wr;b++)//similarly the { -LL w=r*wr+b*WB;Wuyi if(w>c) the Break; -LL big= (c-w)/(wr*WB); WuLL cur=r*hr+b*hb+big*H_big; - if(cur>ans) Aboutans=cur; $ } - } -cout<<ans<<Endl; - return 0; A}
HDU changed a background of the same title Zombie ' s treasure Chest
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <stack> One#include <queue> A#include <sstream> -#include <iomanip> - using namespacestd; thetypedefLong LongLL; - Const intinf=0x4fffffff; - Const intexp=1e-5; - Const intms= A; + ConstLL size= +; - + intMain () A { at intT,kase=1; -scanf"%d",&T); - while(t--) - { - LL C,HR,HB,WR,WB; - //cin>>c>>hr>>hb>>wr>>wb; inCin>>c>>wr>>hr>>wb>>HB; - if(wb>WR) to { + swap (WB,WR); - swap (HB,HR); the } * $ if(wr>size)//cleverly controls complexity at 10e6Panax Notoginseng { -LL ans=0LL; the for(LL r=0; r*wr<=c;r++) + { ALL b= (C-R*WR)/WB; theLL cur=r*hr+b*HB; + if(cur>ans) -cn1=cur; $ } $cout<<"Case #"<<kase++<<": "<<ans<<Endl; - Continue; - } theLL ans=0; -LL H_big=max (wb*hr,wr*HB);Wuyi for(LL r=0; r<wb;r++)//if R>=WB, can form a common multiple weight of big the { - for(LL b=0; b<wr;b++)//similarly Wu { -LL w=r*wr+b*WB; About if(w>c) $ Break; -LL big= (c-w)/(wr*WB); -LL cur=r*hr+b*hb+big*H_big; - if(cur>ans) Aans=cur; + } the } -cout<<"Case #"<<kase++<<": "<<ans<<Endl; $ } the return 0; the}
C. Om Nom and Candies cleverly optimized enumeration, which controls the complexity of the 10E6