Poj 1252 euro efficiency (full backpack multiple times)

Source: Internet
Author: User

Euro Efficiency
Time limit:1000 ms   Memory limit:10000 K
Total submissions:1866   Accepted:848

Description

On January 1st 2002, The Netherlands, and several other European countries abandoned their national currency in favor of the euro. This changed the amount of paying, and not just internationally.
A student buying a 68 guilder book before January 1st coshould pay for the book with one 50 guilder banknote and two 10 guilder banknotes, changing two guilders in change. in short: 50 + 10 + 10-1-1 = 68. other ways of paying were: 50 + 25-5-1-1, or 100-25-5-1-1.either
Way, there are always 5 units (banknotes or coins) involved in the payment process, and it
Cocould not be done with less than 5 units.
Buying a 68 euro book is easier these days: 50 + 20-2 = 68, so only 3 units are involved. this is no coincidence; in your other cases paying with euros is more efficient than paying with guilders. on average the euro is more efficient. this has nothing to do,
Of course, with the value of the euro, but with the units chosen. the units for guilders used to be: 1, 2.5, 5, 10, 25, 50, whereas the units for the euro are: 1, 2, 5, 10, 20, 50.
For this problem we restrict ourselves to amounts up to 100 cents. the euro has coins with values 1, 2, 5, 10, 20, 50 eurocents. in paying an arbitrary amount in the range [1,100] eurocents, on average 2.96 coins are involved, either as payment or as change.
The euro series is not optimal in this sense. with coins 1, 24, 34, 39, 46, 50 an amount of 68 cents can be paid using two coins. the average number of coins involved in paying an amount in the range [1,100] is 2.52.
Calculations with the latter series are more complex, however. that is, mental calculations. these calculations cocould easily be programmed in any mobile phone, which nearly everybody carries around und nowadays. preparing for the future, a committee of the European
Central Bank is studying the efficiency of series of coins, to find the most efficient series for amounts up to 100 eurocents. They need your help.
Write a program that, given a series of coins, calculates the average and maximum number of coins needed to pay any amount up to and including 100 cents. you may assume that both parties involved have sufficient numbers of any coin at their disposal.

Input

The first line of the input contains the number of test cases. each test case is described by 6 different positive integers on a single line: the values of the coins, in ascending order. the first number is always 1. the last number is less than 100.

Output

For each test case the output is a single line containing first the average and then the maximum number of coins involved in paying an amount in the range [1,100]. these values are separated by a space. as in the example, the average shoshould always contain
Two digits behind the decimal point. The maximum is always an integer.

Sample Input

31 2 5 10 20 501 24 34 39 46 501 2 3 7 19 72

Sample output

2.96 52.52 32.80 4

Source

Northwestern Europe 2002

Question: http://poj.org/problem? Id = 1252

Analysis: This question should be well thought of using a backpack, but WAF is finished. Recently, this kind of thinking vulnerability is increasing... =, I thought it would be okay if I had two full backpacks (I was paying, but I was looking for money). Later I found that I could pay for money multiple times, but I didn't actually pay for it multiple times, it's just that the previous status was supposed to be looking for money, and the result was paid. It was to be written several times, and then the money could be added to more than 100. So wawawa finally lost.

Code:

#include<cstdio>#include<iostream>using namespace std;const int mm=11111;int f[mm],a[6];int i,j,t,sum,ans,n;bool flag;int main(){    scanf("%d",&t);    while(t--)    {        for(n=i=0;i<6;++i)scanf("%d",&a[i]),n=max(n,a[i]);        n=max((100-n+1)*n,100);        for(i=0;i<n;++i)f[i]=mm;        ans=sum=f[0]=0;        flag=1;        while(flag)        {            flag=0;            for(i=0;i<6;++i)                for(j=a[i];j<=n;++j)                    if(f[j]>f[j-a[i]]+1)f[j]=f[j-a[i]]+1,flag=1;            for(i=0;i<6;++i)                for(j=n-a[i];j>0;--j)                    if(f[j]>f[j+a[i]]+1)f[j]=f[j+a[i]]+1,flag=1;        }        for(i=1;i<101;++i)sum+=f[i],ans=max(ans,f[i]);        printf("%.2lf %d\n",sum/100.0,ans);    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.