zoukankan      html  css  js  c++  java
  • 2011 Asia Shanghai Regional Contest Problem A

      A: Zombie's Treasure Chest 
    Time Limit (sec) 1.00

        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 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
    

    这题,额滴伤啊!!三个人整了好久没整出来。各种背包,贪心都想了,就是没想到这是一道数学题,用的还是高中的线性规划。。。只能说我太水了T_T

    #include <iostream>
    #include <cstring>
    #include <cstdio>

    using namespace std;

    __int64 solve(int n, int s1, int v1, int s2, int v2){
    __int64 tmp, m, a, b;
    a = n/s1; b = (n%s1)/s2; m = a*v1 + b*v2;
    int i = 0;
    while(a >= 0 && i < 10){
    tmp = a*v1 + ((n-a*s1)/s2)*v2;
    m = tmp > m ? tmp : m;
    a--; i++;
    }
    return m;
    }

    int main(){
    //freopen("data.in", "r", stdin);

    int T, n, s1, v1, s2, v2, cas = 0;
    scanf("%d", &T);
    while(T--){
    scanf("%d%d%d%d%d", &n, &s1, &v1, &s2, &v2);
    __int64 a, b;
    a = solve(n, s1, v1, s2, v2);
    b = solve(n, s2, v2, s1, v1);
    printf("Case #%d: %I64d\n", ++cas, a > b ? a : b);
    }
    return 0;
    }



  • 相关阅读:
    [转]顶点数据压缩
    [转]将某个Qt4项目升级到Qt5遇到的问题
    「05」回归的诱惑:一文读懂线性回归
    AI漫谈:我们距离实现《庆余年》里的五竹叔机器人还有多远?
    “木兰”去哪儿了?被全国700所中小学引入的国产编程语言“木兰”,为何在官网删除了下载链接
    有哪些让人相见恨晚的Python库(一)
    2019年最值得关注的AI领域技术突破及未来展望
    为什么样本方差的分母是n-1?为什么它又叫做无偏估计?
    「04」机器学习、深度学习需要哪些数学知识?
    「03」机器学习、深度学习该怎样入门?
  • 原文地址:https://www.cnblogs.com/vongang/p/2223074.html
Copyright © 2011-2022 走看看