Logo
(追記) (追記ここまで)

7589번 - Balanced Change 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB44231651.613%

문제

When giving change to a customer in a shop, clerks are careful to hand over the minimum number of coins – so unless they have run out of coins of the appropriate denomination they will, for example, always give a customer needing \2ドル in change, one \2ドル coin rather than 2 \1ドル coins or 4 50c coins. It might be that this is not always the best strategy however, when there is an imbalance in the stock of coins. If you have an excess of \1ドル coins in the cash drawer, it might be better to give 2 \1ドル coins to a customer, if only to prevent the \1ドル coin bucket from overflowing. Your task is to devise and test an algorithm to decide what coins to give in change, which tries to balance the stock of coins of each denomination.

More precisely: you have a cash draw with buckets for \2,ドル \1,ドル 50c, 20c and 10c coins. We define imbalance as follows: Let min be the minimum number of coins in any bucket. Then the imbalance is the sum of the squares of the number of coins above the minimum in each bucket. If we have 2, 3, 4, 3, 5 of \2,ドル \1,ドル 50c, 20c and 10c coins respectively: the minimum is 2 and the imbalance is (2-2)2 +(3-2)2 +(4-2)2 +(3-2)2 +(5-2)2 = 0 + 1 +たす 4 +たす 1 +たす 9 = 15. Your task is to write a program to give change in such a way as to minimize the imbalance of the cash remaining in the cash draw. If more than one way of giving cash gives the same imbalance you should use the one which gives the greater number of \2ドル coins. If the number of \2ドル coins is the same, then prefer the one with the largest number of \1ドル coins, then 50c, etc.

입력

The input file contains several change giving problems. Each problem is described on one line of input by 5 integers and a dollar amount. The first 5 are the numbers of \2,ドル \1,ドル 50c, 20c, and 10c coins in the cash drawer. The dollar amount takes the form ‘\$n.m’ where n is always present, but may be zero and m is always two digits. It is the amount of change to be given. Input ends with a line holding 5 zeroes and ‘\0ドル.00’. The amount of change to be given is always greater than zero and never more than \5ドル.

출력

For each problem output a line with ‘Problem #n:’, followed by the number of \2,ドル \1,ドル 50c, 20c and 10c coins respectively. This should be formatted as illustrated below with correct use of commas, and the word ‘and’. If it is not possible to provide exact change, output ‘not possible’.

제한

예제 입력 1

2 2 4 2 2 1ドル.00
0 0 0 0 0 1ドル.00
2 2 4 3 1 1ドル.30
0 0 0 0 0 0ドル.00

예제 출력 1

Problem #1: 2 50c coin(s)
Problem #2: not possible
Problem #3: 2 50c, 1 20c and 1 10c coin(s)

힌트

출처

ICPC > Regionals > South Pacific > South Pacific Region > New Zealand Programming Contest > NZPC 2009 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /