poj 1252 Euro Efficiency(전체 가방 여러 번)
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 1866
Accepted: 848
Description
On January 1st 2002, The Netherlands, and several other European countries abandoned their national currency in favour of the Euro. This changed the ease of paying, and not just internationally.
A student buying a 68 guilder book before January 1st could pay for the book with one 50 guilder banknote and two 10 guilder banknotes, receiving 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
could 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 many 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 could easily be programmed in any mobile phone, which nearly everybody carries around 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 should always contain two digits behind the decimal point. The maximum is always an integer.
Sample Input
3
1 2 5 10 20 50
1 24 34 39 46 50
1 2 3 7 19 72
Sample Output 2.96 5
2.52 3
2.80 4
Source Northwestern Europe 2002
제목:http://poj.org/problem?id=1252
분석: 이 문제는 가방으로 할 생각이 잘 났을 거예요. 그런데 다 하자마자wa가 됐어요. 요즘 이런 사고의 빈틈이 점점 많아지고 있어요.원래는 정반을 두 번 완전히 가방에 넣으면 된다고 생각했는데, 나중에 보니 여러 번 돈을 낼 수도 있다는 것을 알게 되었다. 사실은 여러 번 돈을 낼 수 있는 것이 아니라 이전의 상태에서 돈을 찾아야 했는데 결국 돈을 지불했다. 어쨌든 여러 번 써야 했다. 그 다음에 돈을 100을 넘을 수 있게 되었다. 그래서 wawa, 결국 A가 떨어졌다.
코드:
#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
",sum/100.0,ans);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
less 명령으로 파일을 다시 씁니다.less 명령이란? 텍스트 파일을 한 화면에 표시하는 명령less /var/log/messages 에서 messages 로그 파일을 확인할 수 있습니다. 대체로 확인할 때 less 를 사용하는 것이 많을까 생각합니다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.