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

 

转载于:https://www.cnblogs.com/upstart/p/6783571.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值