acm 1005 纸币问题
2016-03-29 17:53
435 查看
1.1005
2.
[align=left]Problem Description[/align]
"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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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".
[align=left]Sample Input[/align]
3
33 6 6 6 6 6
10 10 10 10 10 10
11 0 1 20 20 20
[align=left]Sample Output[/align]
6 9
1 10
-1 -1
3.有五种钱币的数量:1,5,10,50,100,要求找出钱数固定的两种方案,一种数量最多,一种数量最少
4.手上所有的纸币价格为a,书的钱数为b,花费后的钱数为(a-b),我们可以用最少的纸币去凑(a-b),相减可得剩余最多
5.
#include<cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
using namespacestd;
int themin(intp,int arr[],int a[])
{
int count=0,i,k;
for(i=4;i>=0;i--)
{
if(p>=arr[i]*a[i])
{
p-=arr[i]*a[i];
count+=arr[i];
}
else
{
k=p/a[i];
count+=k;
p-=k*a[i];
}
}
if(p>0) return -1;
else return count;
}
int themax(intp,int arr[],int a[])
{
int sum[10],i,count=0;
sum[0]=arr[0];
for(i=1;i<=4;i++)
sum[i]=sum[i-1]+a[i]*arr[i];
for(i=4;i>0;i--)
{
if(p<=sum[i-1]) continue;
else
{
int t;
t=((p-sum[i-1])/a[i])+(((p-sum[i-1])%a[i])?1:0);
count+=t;
p-=t*a[i];
}
}
if(p>arr[0]) return -1;
else return count+p;
}
int main()
{ int N,i,t;
cin>>N;
int p,a[6]={1,5,10,50,100},arr[6];
while(N--)
{
cin>>p;int sum=0;
for(i=0;i<5;i++)
{
cin>>arr[i];
sum+=arr[i]*a[i];
}
if(sum<p)cout<<-1<<" "<<-1<<endl;
else
{
t=themin(p,arr,a);
if(t==-1)
{
cout<<-1<<""<<-1<<endl;
}
else
{
cout<<t<<""<<themax(p,arr,a)<<endl;
}
}
}
return 0;
}
2.
[align=left]Problem Description[/align]
"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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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".
[align=left]Sample Input[/align]
3
33 6 6 6 6 6
10 10 10 10 10 10
11 0 1 20 20 20
[align=left]Sample Output[/align]
6 9
1 10
-1 -1
3.有五种钱币的数量:1,5,10,50,100,要求找出钱数固定的两种方案,一种数量最多,一种数量最少
4.手上所有的纸币价格为a,书的钱数为b,花费后的钱数为(a-b),我们可以用最少的纸币去凑(a-b),相减可得剩余最多
5.
#include<cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
using namespacestd;
int themin(intp,int arr[],int a[])
{
int count=0,i,k;
for(i=4;i>=0;i--)
{
if(p>=arr[i]*a[i])
{
p-=arr[i]*a[i];
count+=arr[i];
}
else
{
k=p/a[i];
count+=k;
p-=k*a[i];
}
}
if(p>0) return -1;
else return count;
}
int themax(intp,int arr[],int a[])
{
int sum[10],i,count=0;
sum[0]=arr[0];
for(i=1;i<=4;i++)
sum[i]=sum[i-1]+a[i]*arr[i];
for(i=4;i>0;i--)
{
if(p<=sum[i-1]) continue;
else
{
int t;
t=((p-sum[i-1])/a[i])+(((p-sum[i-1])%a[i])?1:0);
count+=t;
p-=t*a[i];
}
}
if(p>arr[0]) return -1;
else return count+p;
}
int main()
{ int N,i,t;
cin>>N;
int p,a[6]={1,5,10,50,100},arr[6];
while(N--)
{
cin>>p;int sum=0;
for(i=0;i<5;i++)
{
cin>>arr[i];
sum+=arr[i]*a[i];
}
if(sum<p)cout<<-1<<" "<<-1<<endl;
else
{
t=themin(p,arr,a);
if(t==-1)
{
cout<<-1<<""<<-1<<endl;
}
else
{
cout<<t<<""<<themax(p,arr,a)<<endl;
}
}
}
return 0;
}
相关文章推荐
- HDU 2147 博弈
- iOS地图
- 桶排序 【Java】
- 【iOS】UITextView 自动跳动的问题
- 自动化实施需考虑点
- Elman反馈网络 预测 解决时间序列问题
- spring启动过程之源码跟踪(下)--spring Debug
- Android-drawable-shape
- 没有建联合索引导致cpu过高
- 课本第十八章读书笔记
- 解决Redis Cluster模式下的排序问题
- 作业4:结对项目—— 词频统计【必做2】
- POJ1281
- 科大讯飞--让你的APP学会说学逗唱
- hashmap和ConcurrentHashMap相关问题
- Laravel5入门
- android 用canvas绘制虚线
- 无限轮播 实现原理
- HDU1051切割木头
- Tomcat6的项目迁移到weblogic11g时报错