hdu5527Too Rich
来源:互联网 发布:电脑看书软件阅读器 编辑:程序博客网 时间:2024/05/01 21:38
Too Rich
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 401 Accepted Submission(s): 119
Problem Description
You are a rich person, and you think your wallet is too heavy and full now. So you want to give me some money by buying a lovely pusheen sticker which costs p dollars from me. To make your wallet lighter, you decide to pay exactly p dollars by as many coins and/or banknotes as possible.
For example, ifp=17 and you have two $10 coins, four $5 coins, and eight $1 coins, you will pay it by two $5 coins and seven $1 coins. But this task is incredibly hard since you are too rich and the sticker is too expensive and pusheen is too lovely, please write a program to calculate the best solution.
For example, if
Input
The first line contains an integer T indicating the total number of test cases. Each test case is a line with 11 integers p,c1,c5,c10,c20,c50,c100,c200,c500,c1000,c2000 , specifying the price of the pusheen sticker, and the number of coins and banknotes in each denomination. The number ci means how many coins/banknotes in denominations of i dollars in your wallet.
1≤T≤20000
0≤p≤109
0≤ci≤100000
Output
For each test case, please output the maximum number of coins and/or banknotes he can pay for exactly p dollars in a line. If you cannot pay for exactly p dollars, please simply output '-1'.
Sample Input
317 8 4 2 0 0 0 0 0 0 0100 99 0 0 0 0 0 0 0 0 02015 9 8 7 6 5 4 3 2 1 0
Sample Output
9-136
Source
2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)
题目大意是给你一些固定面额的钱的数量以及一个值X,然后让你用最多数量的钱拼出X。
先不问题转换一下,改为拼出(总额-x),如果没有50面额和500面额的话就是贪心了。那就合并两个50面额成为100,合并500成为1000,暴力枚举是否用了50,500
#include<bits/stdc++.h>using namespace std;const int val[]={1,5,10,20,50,100,200,500,1000,2000};int c[11],ans,tot,sum,p;void update(int x,int tmp,int s1,int s2){ if(x<0)return; for(int i=9;i>=0;i--){ //printf("%d %d %d %d %d %d\n",x,c[i],val[i],tmp,s1,s2); if(i==4){ if(x>=100*s1){ x-=100*s1; tmp-=s1*2; }else{ tmp-=x/100*2; x%=100; } continue; } if(i==7){ if(x>=1000*s2){ x-=1000*s2; tmp-=s2*2; }else{ tmp-=x/1000*2; x%=1000; } continue; } if(x>=c[i]*val[i]){ x-=c[i]*val[i]; tmp-=c[i]; }else{ tmp-=x/val[i]; x%=val[i]; } } // printf("%d %d\n",x,tmp); if(x==0)ans=max(tmp,ans);}void work(){ ans=-1;tot=sum=0; scanf("%d",&p); for(int i=0;i<10;i++){ scanf("%d",c+i); tot+=val[i]*c[i]; sum+=c[i]; } if(tot<p){ printf("-1\n"); return; } if(tot==p){ printf("%d\n",sum); return; } // printf("tot =%d sum= %d p= %d\n",tot,sum,p); update(tot-p,sum,c[4]/2,c[7]/2); if(c[4]&&c[7]) update(tot-p-50-500,sum-2,(c[4]-1)/2,(c[7]-1)/2); if(c[4]) update(tot-p-50,sum-1,(c[4]-1)/2,c[7]/2); if(c[7]) update(tot-p-500,sum-1,c[4]/2,(c[7]-1)/2); printf("%d\n",ans);}int main(){ int t;scanf("%d",&t); while(t--)work(); return 0;}
0 0
- hdu5527Too Rich
- Richfaces rich:panelBar rich:panelBarItem rich:panelMenu
- Rich Client
- Filthy Rich
- Rich Text
- Filthy Rich
- Rich Text
- Rich Internet Application or Rich Interactivity Application?
- rich:datatable和 rich:subtable区别
- Rich Client技术简介
- Rich Client技术简介
- Rich Client技术简介
- Rich Client技术简介
- Why Ajax rich clients?
- Rich Client技术简介
- Spring Rich Client Databinding !?
- Rich Internet applications (RIAs)
- 关于rich:fileUpload学习心得
- Stooge sort: Sorting by Exchanging
- 窗口,控件:捕捉焦点
- PHP高级程序设计——抽象类
- UItableView 的使用总结
- 链表自定义队列
- hdu5527Too Rich
- 懒加载
- c#写事物
- javaScript细节之生成不重复的随机数
- MFC总结(13) -- 在mfc中使用线程 更新Progress Control(2)
- 天猫春晚:罅隙密布的消费主义神话
- jquery 选同名input值
- 基于深度学习的人脸识别项目已经接近尾声了
- IONIC 移到开发本地相册图片转换成base64