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



  • 相关阅读:
    c++ 网络编程(四) LINUX/windows下 socket 基于I/O复用的服务器端代码 解决多进程服务端创建进程资源浪费问题
    c++ 网络编程(三) LINUX/windows 进程间的通信原理与实现代码 基于多进程的服务端实现
    c++ 网络编程(二) linux 下多进程socket通信 多个客户端与单个服务端交互代码实现回声服务器
    c++ 网络编程(一)TCP/UDP windows/linux 下入门级socket通信 客户端与服务端交互代码
    c++ MFC图像处理CImage类常用操作代码
    vue 模板语法
    占位1
    MongoDB
    Node.js fs-文件系统
    nodeJs 常用模块(一)
  • 原文地址:https://www.cnblogs.com/vongang/p/2223074.html
Copyright © 2011-2022 走看看