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
题意:有1 5 10
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的更多相关文章

  1. 实验12:Problem F: 求平均年龄

    Home Web Board ProblemSet Standing Status Statistics   Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...

  2. 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 ...

  3. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  4. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  5. 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 ...

  6. Problem F: Exponentiation

    Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...

  7. Problem F: 合唱比赛开始了!

    Problem F: 合唱比赛开始了! Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 440  Solved: 201[Submit][Status][ ...

  8. 几何入门合集 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个 ...

  9. Problem F Plug It In!

    题目链接:https://cn.vjudge.net/contest/245468#problem/F 大意:给你插座和电器的对应关系,有多个电器对应一个插座的情况,但是一个插座只能供一个电器使用,现 ...

  10. 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 ...

随机推荐

  1. 我是如何利用Hadoop做大规模日志压缩的

    背景 刚毕业那几年有幸进入了当时非常热门的某社交网站,在数据平台部从事大数据开发相关的工作.从日志收集.存储.数据仓库建设.数据统计.数据展示都接触了一遍,比较早的赶上了大数据热这波浪潮.虽然今天的人 ...

  2. 进入css3动画世界(一)

    其实我做css3动画也没有多久,这篇文章目标人群是css3动画的新手,不喜勿喷. 分类 目前我接触到的css3动画有2类:一种是transition的,另一种是@keyframes的. 两者的区别就是 ...

  3. JAVA设计模式总结之六大设计原则

    从今年的七月份开始学习设计模式到9月底,设计模式全部学完了,在学习期间,总共过了两篇:第一篇看完设计模式后,感觉只是脑子里面有印象但无法言语.于是决定在看一篇,到9月份第二篇设计模式总于看完了,这一篇 ...

  4. Codeforces 858A. k-rounding 数论

    题目: 题意:输入n和k,找到一个最小的数,满足末尾有至少k个0和是n的倍数. 最小的情况 ans = n,最大的情况 ans = n*pow(10,k). 令 k = pow(10,k); 我们发现 ...

  5. hdu 4123--Bob’s Race(树形DP+RMQ)

    题目链接 Problem Description Bob wants to hold a race to encourage people to do sports. He has got troub ...

  6. Clojure——学习迷宫生成

    背景 初学clojure,想着看一些算法来熟悉clojure语法及相关算法实现. 找到一个各种语言生成迷宫的网站:http://rosettacode.org/wiki/Maze_generation ...

  7. 《算法导论》学习总结 — XX.第23章 最小生成树

    一.什么叫最小生成树 一个无向连通图G=(V,E),最小生成树就是联结所有顶点的边的权值和最小时的子图T,此时T无回路且连接所有的顶点,所以它必须是棵树. 二.为什么要研究最小生成树问题 <算法 ...

  8. VB.net DateTimePicker 初始化为空,选择后显示日期

    目的:当某记录的日期数据为空的时候,DateTimePicker 不以默认当前时间显示. 优点:避免不规则的时间格式输入:符合平时遇到的时间输入习惯 缺点:设置要代码,没有textbox控件那么方便设 ...

  9. windows下PHP中Fatal error Call to undefined function curl_init()的解决方法

    参考官方解决方法:http://nz.php.net/manual/en/curl.installation.php 1.php安装目录下的ext文件夹下面是否有php_curl.dll文件,然后右键 ...

  10. webview的javascript与Native code交互

    http://my.oschina.net/u/1376187/blog/172296 项目中使用了webview显示网页,其中需要网页和native方法有交互,搜索到一篇文章,转发分享一下: === ...