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 ...
随机推荐
- Jquery Ajax type的4种类型
Ajax type这个里面填什么呢?通常大家都会说get和post.那么还有2个是什么呢 $.ajax({ url: 'http://www.cnblogs.com/youku/', type: '' ...
- java中Set类接口的用法
在Java中使用Set,可以方便地将需要的类型,以集合类型保存在一个变量中.主要应用在显示列表. Set是一个不包含重复元素的collection.更确切地讲,set 不包含满足 e1.equals( ...
- [js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解
路径在canvas绘图中,经常被用到,是一个非常重要的概念. 比如:我们要在canvas画出3条直线,要求用不同的颜色加以区分. <style> body { background: #0 ...
- HDFS概述(4)————HDFS权限
概述 Hadoop分布式文件系统(HDFS)的权限模型与POSIX模型的文件和目录权限模型一致.每个文件和目录与所有者和组相关联.该文件或目录将权限划分为所有者的权限,作为该组成员的其他用户的权限.以 ...
- Java总结篇:Java多线程
Java总结篇系列:Java多线程 多线程作为Java中很重要的一个知识点,在此还是有必要总结一下的. 一.线程的生命周期及五种基本状态 关于Java中线程的生命周期,首先看一下下面这张较为经典的图: ...
- PHP字符串替换str_replace()函数4种用法详解
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )该函数返回一个字符串 ...
- 【原创】修复ios输入框获取焦点时不支持fixed的bug
前些日子,做了一个手机站的项目,有一个页面是这样的, 有一个固定(position:fixed)的头部和底部导航,中间是一些表单内容,没啥特别的.但是到了ios中,正常滚动页面没有问题,一旦触发了文本 ...
- 学习flex布局(弹性布局)
Flex是Flexible Box的缩写,意为弹性布局.是W3C早期提出的一个新的布局方案.可以便捷的实现页面布局,目前较高版本的主流浏览器都能兼容,兼容情况如下: Flex在移动端开发上已是主流,比 ...
- c语言构造类型之数组_01
构造类型--constructed type.至于定义,笔者就省略了,有兴趣的同学可以百度搜索https://www.baidu.com/.今天我们要说的是c语言中最简单的构造类型--数组(array ...
- linux 内核 zImage 生成过程分析
1. 依据arch/arm/kernel/vmlinux.lds 生成linux内核源码根目录下的vmlinux,这个vmlinux属于未压缩,带调试信息.符号表的最初的内核,大小约23MB: arm ...