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



  • 相关阅读:
    从架构演进的角度聊聊Spring Cloud都做了些什么?
    Spring Cloud在国内中小型公司能用起来吗?
    中小型互联网公司微服务实践-经验和教训
    springcloud(十二):使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪
    springcloud(十一):服务网关Zuul高级篇
    springcloud(十):服务网关zuul初级篇
    springcloud(九):配置中心和消息总线(配置中心终结版)
    [讨论]C++编译/编辑器对OIer的必要功能
    [题解]How Many Tables HDU
    [干货]文件输入输出实例&Ptask的编写
  • 原文地址:https://www.cnblogs.com/vongang/p/2223074.html
Copyright © 2011-2022 走看看