您的位置:首页 > 其它

2016SDAU课程练习一1005

2016-03-26 14:24 288 查看
Problem F 

Problem Description

"Yakexi, this is the best age!" Dong MW works hard and get high pay, he has many 1 Jiao and 5 Jiao banknotes(纸币), some day he went to a bank and changes part of his money into 1 Yuan, 5 Yuan, 10 Yuan.(1 Yuan = 10 Jiao)

"Thanks to the best age, I can buy many things!" Now Dong MW has a book to buy, it costs P Jiao. He wonders how many banknotes at least,and how many banknotes at most he can use to buy this nice book. Dong MW is a bit strange, he doesn't like to get the change,
that is, he will give the bookseller exactly P Jiao.

 

Input

T(T<=100) in the first line, indicating the case number. T lines with 6 integers each: P a1 a5 a10 a50 a100 ai means number of i-Jiao banknotes. All integers are smaller than 1000000.

 

Output

Two integers A,B for each case, A is the fewest number of banknotes to buy the book exactly, and B is the largest number to buy exactly.If Dong MW can't buy the book with no change, output "-1 -1".

 

Sample Input

3

33 6 6 6 6 6

10 10 10 10 10 10

11 0 1 20 20 20 

Sample Output

6 9

1 10
-1 -1

题意:给出一块 五块 十块 五十块 一百块的数量,凑一个金额,最多和最少用多少纸币

思路:最少的话,就是从大到小,最多的话借鉴了别人的,就是手里剩余的纸币最少

感想:晕不拉几晕不拉几。。。

AC代码:

#include<iostream>  

#include<string.h>  

#include<set>  

#include<stdio.h>  

#include<vector>  

#include<algorithm>  

#include<numeric>  

#include<math.h>  

#include<string.h>  

#include<sstream>  

#include<stdio.h>  

#include<string>  

#include<cstdlib>  

#include<algorithm>  

#include<iostream>  

#include<map>  

#include<queue>  

#include<string>  

using namespace std;  

int b[10]={0,1,5,10,50,100};  

int main()  

{  

    int t;  

    int p,r;  

    int a[10],c[10],e[10];  

    int i,j,k,sum;  

  

    cin>>t;;  

    while(t--)  

    {  

        sum=0;  

        cin>>p;            

        r=p;  

        for(i=1;i<=5;i++)  

        {  

            cin>>a[i];  

            sum=sum+b[i]*a[i];     

        }  

        for(i=5;i>0;i--)  

        {  

            if(r/b[i]<a[i])  

            {  

                c[i]=r/b[i];  

                r=r-b[i]*c[i];    

  

            }  

            else  

            {  

                c[i]=a[i];              

                r=r-c[i]*b[i];  

            }  

        }  

        if(r!=0)  

        {  

            cout<<"-1"<<" "<<"-1"<<endl;             

  

        }else  

        {  

             k=sum-p;                       

            for(i=5;i>0;i--)  

            {  

                if(k/b[i]<a[i])  

                {  

                    e[i]=k/b[i];  

                    k=k-b[i]*e[i];  

                }  

                else  

                {  

                    e[i]=a[i];  

                    k=k-e[i]*b[i];  

                }  

            }  

            if(k==0)  

            {  

                cout<<c[1]+c[2]+c[3]+c[4]+c[5] ;cout<<" " ;cout<<a[1]+a[2]+a[3]+a[4]+a[5]-e[1]-e[2]-e[3]-e[4]-e[5]<<endl;  

            }  

  

        }  

  

    }  

}  

$(".MathJax").remove();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: