Problem F
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.
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.
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".
6
10 10
20 20
50 100这几种面值的钱,且个数是给定的,给你一个钱数,让你求最多硬币树,和最少硬币数;
#include
#include
#include
using namespace std;
int mina(int a[],int p,int a_m[])
{
int
ans=0;
for(int
i=5;i>1;i--)
{
if(p>=a[i]*a_m[i])//看看当前剩下的钱是不是比枚举到的钱数大
{
ans+=a[i];
p-=a[i]*a_m[i];
}
else//小
{
ans+=p/a_m[i];
p%=a_m[i];
}
if(p>a[1]) return -1;
else return
ans+p;
}
int maxa(int a[],int p,int a_m[],int sum[])
{
int
ans=0;
for(int
i=5;i>1;i--)
{
if(p<=sum[i-1])//p比当前金币的总价值小
continue;
else//大
{
int t;
t=((p-sum[i-1])/a_m[i])+(((p-sum[i-1])%a_m[i])?1:0);
//(p-sum[i-1])是除去当前钱数之前的钱数之和
ans+=t;
p-=t*a_m[i];
//printf("t=%d a[i]_m=%d p=%d\n",t,a_m[i],p);
}
}
//printf("P=%d a[1]=%d\n",p,a[1]);
if(p>a[1]) return -1;
else return
ans+p;
int solve(int a[],int p,int a_m[])
{
int
minn=0,maxn=0;
int
sum[6]={0};
for(int
i=1;i<6;i++)
sum[i]=sum[i-1]+a[i]*a_m[i];
minn=mina(a,p,a_m);
maxn=maxa(a,p,a_m,sum);
//printf("minn=%d maxn=%d\n",minn,maxn);
if(minn==-1)printf("-1 -1\n");
else
{
if(maxn==-1)printf("-1 -1\n");
else
printf("%d %d\n",minn,maxn);
}
}
int main()
{
//freopen("in.txt", "r", stdin);
int
a[6],a_m[6]={0,1,5,10,50,100},sum=0,n,p;
scanf("%d",&n);
for(int
i=0;i
{
memset(a,0,sizeof(a));
scanf("%ld%ld%ld%ld%ld%ld",&p,&a[1],&a[2],&a[3],&a[4],&a[5]);
for(int j=1;j<6;j++)
{
sum+=a_m[j]*a[j];
}
if(sum
else solve(a,p,a_m);
}
return
0;
}
Problem F的更多相关文章
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- Problem F: Exponentiation
Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...
- Problem F: 合唱比赛开始了!
Problem F: 合唱比赛开始了! Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 440 Solved: 201[Submit][Status][ ...
- 几何入门合集 gym101968 problem F. Mirror + gym102082 Problem F Fair Chocolate-Cutting + gym101915 problem B. Ali and Wi-Fi
abstract: V const & a 加速 F. Mirror 题意 链接 问题: 有n个人在y=0的平面上(及xoz平面).z=0平面上有一面镜子(边平行于坐标轴).z=a平面上有q个 ...
- Problem F Plug It In!
题目链接:https://cn.vjudge.net/contest/245468#problem/F 大意:给你插座和电器的对应关系,有多个电器对应一个插座的情况,但是一个插座只能供一个电器使用,现 ...
- 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem F. Judging Time Prediction 优先队列
Problem F. Judging Time Prediction 题目连接: http://www.codeforces.com/gym/100253 Description It is not ...
随机推荐
- js 倒计时(服务器时间同步)
首先说一下,为什么要服务器时间同步, 因为服务器时间和本地电脑时间存在一定的时间差.有些对时效性要求非常高的应用,例如时时彩开奖,是不能容忍这种时间差存在的. 方案1:每次倒计时去服务端请求时间 // ...
- Azure Powershell使用已有Image创建ARM非托管磁盘虚拟机
生成Image映像文件,记录好Image的URL(下面URL为测试URL,具体请参考实际):ImageURL:https://hlmrgstoragen.blob.core.chinacloudapi ...
- oracle pl/sql 包
包用于在逻辑上组合过程和函数,它由包规范和包体两部分组成.1).我们可以使用create package命令来创建包,如:i.创建一个包sp_packageii.声明该包有一个过程update_sal ...
- python对列表的联想
python的列表与字典,已经接触无数次了.但是很多用法都记不住,个人觉得归根原因都是只是学了知识点而少用,也少思考.在此试图用宫殿记忆法对它们的用法做个简单的梳理. 首先,说说列表的删除,删除有三种 ...
- 退出psql时,报psql_history的错
数据库版本:Enterprisedb 9.2(postgreSQL) 错误如下所示: postgres=# exitcould not save history to file "/opt/ ...
- Tensorflow卷积神经网络
卷积神经网络(Convolutional Neural Network, CNN)是一种前馈神经网络, 在计算机视觉等领域被广泛应用. 本文将简单介绍其原理并分析Tensorflow官方提供的示例. ...
- 用sed实现wc -c的功能
sed是所谓的流编辑器,我们经常用它来做一些文本替换的事情,这是sed最擅长的事情,如sed 's/Bob/Tom/g'就是把文章中所有的Bob改成Tom. sed是图灵完备的,作为sed的粉丝,喜欢 ...
- Hudson + SVN + Maven 持续集成实现自动化编译、打包、部署(over SSH 和 Deploy war/ear to a container 两种部署方式)
下载hudson ,安装部署http://hudson-ci.org/ 将下载的hudson-3.3.3.war放到tomcat的webapps目录下并启动tomcat,输入地址访问 点击Instal ...
- 对象反序列化时,抛出java.io.StreamCorruptedException: invalid type code: AC异常
问题描述:在使用java.io.ObjectInputStream类的readObject()方法去读取包含有序列化了多个(两个及两个以上)类的文件时,当读取到第二个类时,会抛出题目中提到的异常. 原 ...
- linux安装禅道的步骤
linux一键安装禅道:1.禅道帮助文档:http://www.zentao.net/book/zentaopmshelp/90.html 2.修改Apache的端口号:/opt/zbox/zbox ...