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



  • 相关阅读:
    EasyUI DataGrid undefined处理
    EasyUI Tabs
    EasyUI ComboBox ajax
    Spring Controller RequestMapping
    Spring前台填充数据
    关于Map集合的遍历总结
    mvc与三层结构终极区别
    关于cron4j的使用
    中国各个省市县的人口统计,echart展示
    windows 安装nodejs 和 npm
  • 原文地址:https://www.cnblogs.com/vongang/p/2223074.html
Copyright © 2011-2022 走看看