zoukankan      html  css  js  c++  java
  • HDU 4091 Zombie’s Treasure Chest 分析 难度:1

    Zombie’s Treasure Chest

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 4442    Accepted Submission(s): 889


    Problem Description
      Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies.
      The warriors are so brave that they decide to defeat the zombies and then bring all the treasures back. A brutal long-drawn-out battle lasts from morning to night and the warriors find the zombies are undead and invincible.
      Of course, the treasures should not be left here. Unfortunately, the warriors cannot carry all the treasures by the treasure chest due to the limitation of the capacity of the chest. Indeed, there are only two types of treasures: emerald and sapphire. All of the emeralds are equal in size and value, and with infinite quantities. So are sapphires.
      Being the priest of the warriors with the magic artifact: computer, and given the size of the chest, the value and size of each types of gem, you should compute the maximum value of treasures our warriors could bring back.
     
    Input
      There are multiple test cases. The number of test cases T (T <= 200) is given in the first line of the input file. For each test case, there is only one line containing five integers N, S1, V1, S2, V2, denoting the size of the treasure chest is N and the size and value of an emerald is S1 and V1, size and value of a sapphire is S2, V2. All integers are positive and fit in 32-bit signed integers.
     
    Output
      For each test case, output a single line containing the case number and the maximum total value of all items that the warriors can carry with the chest.
     
    Sample Input
    2 100 1 1 2 2 100 34 34 5 3
     
    Sample Output
    Case #1: 100
    Case #2: 86
     
    卡题在即使v1/s1>v2/s2且s2>s1
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    long long  n,s1,v1,s2,v2;
    const double eps=1e-11;
    long long gcd(long long a,long long b){
        return b==0?a:gcd(b,a%b);
    }
    long long lcm(long long a,long long b){
    if(a*b==0)return 0;
        return a*b/(gcd(a,b));
    }
    int main(){
        int T;
        scanf("%d",&T);
        for(int ca=1;ca<=T;ca++){
                scanf("%I64d%I64d%I64d%I64d%I64d",&n,&s1,&v1,&s2,&v2);
    if(s1>s2){
        swap(s1,s2);swap(v1,v2);
    }
            long long LCM=lcm(s1,s2);
            long long t1=n>LCM?(n-LCM)/LCM:0;
            n-=t1*LCM;
            long long ans=(n/s1)*v1+((n%s1)/s2)*v2;
            long long a=n/s2;
            for(long long i=0;i<=a;i++){
                long long tmp=(i*v2)+((n-i*s2)/s1)*v1;
                ans=max(ans,tmp);
            }
            ans+=t1*max((LCM/s1)*v1,(LCM/s2)*v2);
            printf("Case #%d: %I64d\n",ca,ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    33.数组声明方式(var构造函数) 、检测数组类型、数组的属性(封装好的就一个length)、数组的方法
    31.this指向(写出调用链,找最近对象) this的默认绑定 隐式绑定 显示绑定(call(绑定对象) apply(绑定对象) 当括号内没放绑定对象的时候恢复默认绑定) bind
    31.
    30.函数作用域链 (GO AO 也叫词法作用域链)、 调用栈、调用栈涉及this绑定
    29.包装类(构造函数) 包装类作用及调用栈
    916. Word Subsets
    246. Strobogrammatic Number
    445. Add Two Numbers II
    2. Add Two Numbers
    341. Flatten Nested List Iterator
  • 原文地址:https://www.cnblogs.com/xuesu/p/3978954.html
Copyright © 2011-2022 走看看