Hdu 2021 Salary: (greedy) _ Greedy

Source: Internet
Author: User
Tags prepare first row

Description
As the teacher of hang-electric, the most hope of the day is 8th a month, because this day is the day of payday, the breadwinner depends on it, hehe, but for the staff of the school Finance Department, This day is a very busy day, the finance department's Mr. Hu has recently been thinking about a problem: if each teacher's salary is known, the minimum need to prepare how many yuan, in order to give each teacher pay when the teachers do not need to change it. This assumes that the teacher's salary is a positive integer, Unit yuan, a total of 100 yuan, 50 yuan, 10 yuan, 5 yuan, 2 yuan and 1 yuan six kinds of
input
input data contains multiple test instances, the first row of each test instance is an integer n (n <100), indicating the number of teachers, and then n a teacher's salary. N=0 represents the end of the input and does not handle
output
to output an integer x for each test instance that represents the minimum number of RMB to prepare. One row for each output
Sample Input
3
1 2 3
0
Sample Output
4
solution
Simple greed, it is obvious to spend as much as possible to make the number of RMB sheets prepared at least
Code

 #include <cstdio> #include <iostream> using namespace std; int main () {int n;
        while (scanf ("%d", &n), n) {int d,ans=0;
            for (int i=0;i<n;i++) {scanf ("%d", &d);
            ans+=d/100;d%=100;
            ans+=d/50;d%=50;
            ans+=d/10;d%=10;
            ans+=d/5;d%=5;
            ans+=d/2;d%=2;
        Ans+=d;
    printf ("%d\n", 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.