C. Om Nom and Candies cleverly optimized enumeration, which controls the complexity of the 10E6

Source: Internet
Author: User
Tags cmath

                                    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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.