UVa 12325 Treasure Chest

Source: Internet
Author: User

https://vjudge.net/problem/UVA-12325

Test instructions: There is a box with a volume of N and two infinite treasures. The volume of the Treasure 1 is S1, the value of V1 ' Treasure 2 of the volume of S2, the value of V2. Calculate the maximum amount of valuable treasures to be loaded.

The idea: The topic is very clear is the violent enumeration, but if does not simplify the enumeration the words certainly will be timed out, if N/S1 is smaller, then enumerates the number of Treasures 1, if N/S2 is smaller, enumerates the number of Treasures 2. There is also a situation is S1 and S2 are very small, S2 treasure 1 and S1 Treasure 2 of the same volume, and the value of S2*V1 and S1*v2 respectively. If the former is larger, then the Treasure 2 will only take s1-1 (otherwise S1 a treasure 2 to S2 1), if the latter is larger, then the Treasure 1 will only take s2-1.

1#include <iostream>2 using namespacestd;3 4 Long LongN, S1,v1, S2,v2;5 Long LongMAXN;6 7 voidsolve1 ()8 {9      for(inti =0; I <= n/s1; i++)Ten     { One         Long LongNumber = (N-I*S1)/S2; A         Long Longsum = i*v1 + number*V2; -         if(Sum > MAXN) maxn=sum; -     } the } -  - voidsolve2 () - { +      for(inti =0; I <= n/s2; i++) -     { +         Long LongNumber = (N-I*S2)/S1; A         Long Longsum = i*v2 + number*V1; at         if(Sum > MAXN) maxn=sum; -     } - } -  - voidsolve3 () - { in     if(s2*v1<s1*V2) -     { to          for(inti =0; I < S2 && i<=n/s1; i++) +         { -             Long LongNumber = (N-I*S1)/S2; the             Long Longsum = i*v1 + number*V2; *             if(Sum > MAXN) MAXN =sum; $         }Panax Notoginseng     } -     Else the     { +          for(intI=0; I < s1&&i<=n/s2; i++) A         { the             Long LongNumber = (N-I*S2)/S1; +             Long Longsum = i*v2 + number*V1; -             if(Sum > MAXN) MAXN =sum; $         } $     } - } -  the intMain () - {Wuyi     intN, Kase =0; theCIN >>N; -      while(n--) Wu     { -CIN >> N >> S1 >> V1 >> S2 >>V2; AboutMAXN =0; $         if(s1< -&& s2< -)  - solve3 (); -         Else if(N/s1 < N/S2) solve1 (); -         Elsesolve2 (); Acout <<"Case #"<< ++kase <<": "<< MAXN <<Endl; +     } the     return 0; -}

UVa 12325 Treasure Chest

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.