Pick apples 第三届acm省赛

Description

Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because she has never seen so many apples before. Each kind of apple has a size and a price to be sold. Now the little girl wants to gain more profits, but she does not know how. So she asks you for help, and tell she the most profits she can gain.

Input

In the first line there is an integer T (T <= 50), indicates the number of test cases.
In each case, there are four lines. In the first three lines, there are two integers S and P in each line, which indicates the size (1 <= S <= 100) and the price (1 <= P <= 10000) of this kind of apple.

In the fourth line there is an integer V,(1 <= V <= 100,000,000)indicates the volume of the girl‘s bag.

Output

For each case, first output the case number then follow the most profits she can gain.

Sample Input

1
1 1
2 1
3 1
6

Sample Output

Case 1: 6
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct N
{
    int s,p;
    double pri;
} node[4];
bool cmp(N a,N b)
{
    if(a.pri<b.pri)        return true;
    return false;
}
long long llmax(long long a,long long b)
{
    return a>b?a:b;
}
int main()
{
    int t;
    cin>>t;
    int c=1;
    while(t--)
    {
        for(int i=0;i<3;i++){
            cin>>node[i].s>>node[i].p;
            node[i].pri = 1.0*node[i].s/(1.0*node[i].p);
        }
        int V;
        cin>>V;
        sort(node,node+3,cmp);
        long long ans=0;
        for(int i=0; i<node[0].s; i++)
        {
            for(int j=0; j<node[0].s; j++)
            {
                long long temp=i*node[1].s+j*node[2].s;
                if(temp>V)
                    break;
                else
                {
                    long long v=V-temp;
                    ans=llmax(ans,v/node[0].s*node[0].p+i*node[1].p+j*node[2].p);
                }
            }
        }
        cout<<"Case "<<c++<<": "<<ans<<endl;
    }
    return 0;
}
时间: 2024-08-10 18:33:53

Pick apples 第三届acm省赛的相关文章

Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)

本文出处:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2411 题意:给你一个串,让你依据那个串来输出ppi.坑特别多.ppi的计算方法是dp / inches; dp = sqrt(wp*wp + hp * hp); 现在我来说说这个题目有多坑: 给你的串的格式是这样: name + inches+ "inches"

Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

Time Limit: 5000MS Memory limit: 65536K 题目描写叙述 Haveyou ever played a popular game named "Fruit Ninja"? Fruit Ninja (known as Fruit Ninja HD on the iPad and Fruit Ninja THD for NvidiaTegra 2 based Android devices) is a video game developed by Hal

sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛

本文出自:http://blog.csdn.net/svitter/ 题意:三种苹果,每种都有对应的Size,Value,给你一个背包空间,求最大的价值. 本题目的关键就在于非常大的背包空间 依据indicates the size (1 <= S<= 100) 我们可以考虑在1000000(100^3)之外的空间放性价比最高的苹果.为什么时100^3? 要知道背包如果正好填满,而填满空间相应价值的苹果大于不填满的价值的苹果,那么就选择能填满空间而使价值最大的苹果,而非性价比最高的苹果--性价

河南省第三届acm省赛 AMAZING AUCTION

AMAZING AUCTION 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 Recently the auction house has introduced a new type of auction, the lowest price auction. In this new system, people compete for the lowest bid price, as opposed to what they did in the past. Wh

[2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)

Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because she

[2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)

Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because s

Mine Number(搜索,暴力) ACM省赛第三届 G

1 安装及下载client 端 2 什么是SVN(Subversion)? 3 为甚么要用SVN? 4 怎么样在Windows下面建立SVN Repository? 5 建立一个Working目录 6 新增档案及目录到Repository中 7 更新档案及目录 8 更新至特定版本 9 复制档案及目录 10 制作Tag或是Release 11 快速参考 11.1 取得(Checkout)Repository 11.2 更新(Update)档案或目录 11.3 新增(Add)档案或目录 11.4 提

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)

Pixel density Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Pixels per inch (PPI) or pixel density is a measurement of the resolution of devices in various contexts; typically computer displays, image scanners, and digital camera image s