zoukankan      html  css  js  c++  java
  • UVA

      A: Zombie's Treasure Chest 

    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$ le$200) is given in the first line of the input file. For each test case, there is only one line containing five integers NS1V1S2,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 S2V2All 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
    
    
    
    
    
    
    
    
    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int N; cin >> N;
        for(int n = 1; n <= N; n++)
        {
            long long int h, h1, v1, h2, v2;
            cin>>h>>h1>>v1>>h2>>v2;
            if(h1 < h2){
                swap(h1, h2);
                swap(v1, v2);
            }
            printf("Case #%d: ", n);
            if(h1 > 102400){
                long long int res = 0;
                for(int i = 0; i*h1 <= h; i++)
                    res = max(res, i*v1 + (h-i*h1)/h2*v2);
                printf("%lld
    ", res);
            }
            else{
                if(h2*v1 < h1*v2){
                    swap(h1, h2);
                    swap(v1, v2);
                }
                long long int res = 0;
                for(int i = 0; i <= h1 && i*h2 <= h; i++)
                    res = max(res, i*v2+(h-i*h2)/h1*v1);
                printf("%lld
    ", res);
            }
        }
        return 0;
    }


  • 相关阅读:
    mina简介
    idea编辑器jdk版本报错
    设计模式之-工厂模式
    设计模式之-外观模式
    ssm项目中bean注入失败,获取spring中指定bean之解决方案
    Jquery.Page.js 分页插件的使用
    发现某网站低级致命漏洞引发的对多用户系统安全性讨论
    C#微信公众号开发之网页授权oauth2.0获取用户基本信息(一)
    有关C#中使用if else和try catch的问题及效率问题
    C#伪静态实现的方法
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312767.html
Copyright © 2011-2022 走看看