Pick apples 第三屆acm省賽

來源:互聯網
上載者:User

標籤:produce   input   eve   style   hid   ini   and   class   algo   

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

11 12 13 16

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

 

Pick apples 第三屆acm省賽

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.