poj1252 Euro Efficiency-程序员宅基地

技术标签: poj1252 Euro Efficie  poj1252  poj  dp  

Euro Efficiency
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3936   Accepted: 1694

Description

On January 1st 2002, The Netherlands, and several other European countries abandoned their national currency in favour of the Euro. This changed the ease of paying, and not just internationally. 
A student buying a 68 guilder book before January 1st could pay for the book with one 50 guilder banknote and two 10 guilder banknotes, receiving two guilders in change. In short:50+10+10-1-1=68. Other ways of paying were: 50+25-5-1-1, or 100-25-5-1-1.Either way, there are always 5 units (banknotes or coins) involved in the payment process, and it 
could not be done with less than 5 units. 
Buying a 68 Euro book is easier these days: 50+20-2 = 68, so only 3 units are involved.This is no coincidence; in many other cases paying with euros is more efficient than paying with guilders. On average the Euro is more efficient. This has nothing to do, of course, with the value of the Euro, but with the units chosen. The units for guilders used to be: 1, 2.5, 5, 10, 25, 50,whereas the units for the Euro are: 1, 2, 5, 10, 20, 50. 
For this problem we restrict ourselves to amounts up to 100 cents. The Euro has coins with values 1, 2, 5, 10, 20, 50 eurocents. In paying an arbitrary amount in the range [1, 100] eurocents, on average 2.96 coins are involved, either as payment or as change. The Euro series is not optimal in this sense. With coins 1, 24, 34, 39, 46, 50 an amount of 68 cents can be paid using two coins.The average number of coins involved in paying an amount in the range [1, 100] is 2.52. 
Calculations with the latter series are more complex, however. That is, mental calculations.These calculations could easily be programmed in any mobile phone, which nearly everybody carries around nowadays. Preparing for the future, a committee of the European Central Bank is studying the efficiency of series of coins, to find the most efficient series for amounts up to 100 eurocents. They need your help. 
Write a program that, given a series of coins, calculates the average and maximum number of coins needed to pay any amount up to and including 100 cents. You may assume that both parties involved have sufficient numbers of any coin at their disposal. 

Input

The first line of the input contains the number of test cases. Each test case is described by 6 different positive integers on a single line: the values of the coins, in ascending order. The first number is always 1. The last number is less than 100. 

Output

For each test case the output is a single line containing first the average and then the maximum number of coins involved in paying an amount in the range [1, 100]. These values are separated by a space. As in the example, the average should always contain two digits behind the decimal point. The maximum is always an integer. 

Sample Input

3
1 2 5 10 20 50
1 24 34 39 46 50
1 2 3 7 19 72

Sample Output

2.96 5
2.52 3
2.80 4

Source

Northwestern Europe 2002


题目来源:http://poj.org/problem?id=1252

题目意思与思路:给出六种硬币,问用这些硬币求1-100元能用这六种硬币构成的最小硬币数,比如1 2 5 10 20 50来得到68有(50+20-2),(50+10+5+2+1)等,所以能构成68的最小硬币数为3....

就是简单的完全背包问题,直接套模板...

主要注意的问题是上限问题,因为100以内的数能由100以外的数找零得到(测试了很多次,maxn大概取到1200).



代码如下:

#include <stdio.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
using namespace std;

const int inf = 0x3f3f3f3f;
const int maxn = 1200;

int coin[6];
int dp[maxn];

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        fill(dp, dp+maxn, inf);
        dp[0] = 0;
        for(int i = 0; i < 6; i++)
            scanf("%d", &coin[i]);
        for(int i = 0; i < 6; i++)
            for(int j = coin[i]; j < maxn; j++)
                dp[j] = min(dp[j], dp[j-coin[i]]+1);
        for(int i = 0; i < 6; i++)
            for(int j = maxn-coin[i]-1; j > 0; j--)
                dp[j] = min(dp[j], dp[j+coin[i]]+1);
        double ans = 0;
        int cnt = 0;
        for(int i = 1; i <= 100; i++)
            ans += dp[i], cnt = max(cnt, dp[i]);
        printf("%.2lf %d\n", ans/100.0, cnt);
    }
    return 0;
}


版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_24656715/article/details/52239849

智能推荐

[原创]Chorme密码读取工具\Firefox密码读取工具_chorme登陆过但忘记密码-程序员宅基地

文章浏览阅读301次。工具: getBrowserPWD编译: VC作者: K8哥哥博客: http://qqhack8.blog.163.com发布: 2017/11/24 16:16:17简介: 有时为了方便我们会让浏览器保存网站登陆帐号密码浏览器密码读取工具支持(Chrome/Firefox),VC版无需.net环境GitHub上有.net界面版和python..._chorme登陆过但忘记密码

Google的十个核心技术(转)-程序员宅基地

文章浏览阅读516次。本篇将主要介绍Google的十个核心技术,而且可以分为四大类:1.分布式基础设施:GFS,Chubby和Protocol Buffer。2.分布式大规模数据处理:MapReduce和Sawzall。3.分布式数据库技术:BigTable和数据库Sharding。4.数据中心优化技术:数据中心高温化,12V电池和服务器整合。分布式基础设施GFS由于搜索引擎需要..._sole核心技术

Linux - 运行 python 脚本时报错:Matplotlib is building the font cache; this may take a moment_matplotlib is building the font cache; this may ta-程序员宅基地

文章浏览阅读1k次。缓存文件,但是删除缓存后,还是不行,不清楚具体是什么,但是第二天,脚本就可以正常运行了。_matplotlib is building the font cache; this may take a moment.

蓄水池采样_蓄水池取样-程序员宅基地

文章浏览阅读187次。蓄水池采样前言一、蓄水池抽样算法原理二、题目练习1.链表随机节点3822.随机数索引(398)总结前言给定一个数据流,数据流长度NNN非常大,且NNN直到处理完所有数据之前都不可知,要求遍历一遍就可以找到目标值。一、蓄水池抽样算法原理原理:蓄水池抽样是一系列的随机算法,其目的在于从包含 nnn个项目的集合 SSS 中选取 kkk 个样本,其中 nnn 为一很大或未知的数量,尤其适用于不能把所有 nnn 个项目都存放到内存的情况。二、题目练习1.链表随机节点382给定一个单链表,随机选择链_蓄水池取样

利用Fluent的FFT运算求得频谱的总结_fluent fft-程序员宅基地

文章浏览阅读2.8k次。利用Fluent的FFT运算求得频谱的总结先在Fluent的菜单中选取Surface-Point 在模型中选取监测点,注意:鼠标右键点击是选取监测点,也可以直接输入坐标;https://wenku.baidu.com/view/a72b321452ea551810a6874a.html..._fluent fft

SpringBoot请求参数加密、响应参数解密_springboot 拦截器对post请求进行加解密处理-程序员宅基地

文章浏览阅读1.1k次,点赞7次,收藏9次。SpringBoot请求参数加密、响应参数解密_springboot 拦截器对post请求进行加解密处理

随便推点

[proxy:0:0@WORKSTATION-DEV] HYDU_sock_write (utils/sock/sock.c:256): write error (Broken pipe)_[proxy:0:1@58264c013f86] launch_procs (./pm/pmiser-程序员宅基地

文章浏览阅读2k次。[proxy:0:0@WORKSTATION-DEV] HYDU_sock_write (utils/sock/sock.c:256): write error (Broken pipe)_[proxy:0:1@58264c013f86] launch_procs (./pm/pmiserv/pmip_cb.c:648): unable t

前端性能测试工具Lighthouse_lighthouse accessibility-程序员宅基地

文章浏览阅读8k次,点赞2次,收藏23次。在前端开发中,对于自己开发的app或者web page性能的好坏,一直是让前端开发很在意的话题。我们需要专业的网站测试工具,让我们知道自己的网页还有哪些需要更为优化的方面,我自己尝试了一款工具:Lighthouse,感觉还不错,记录下来,也顺便分享给用得着的伙伴。Lighthouse分析web应用程序和web页面,收集关于开发人员最佳实践的现代性能指标和见解,让开发人员根据生成的评估页面,来进行网站优化和完善,提高用户体验..._lighthouse accessibility

统计推断结果的可视化(卡方分布,t分布,F分布)_卡方检验有办法可视化吗-程序员宅基地

文章浏览阅读290次。卡方检验是利用卡方分布来检验总体的某种假设,主要用于类别变量的推断,比图,一个类别变量的拟合优度,两个类别变量的独立性检验等。下面检验并可视化以下假设:①不同满意度的人数分布是否有显著差异。②网购次数与满意度是否独立。上图是该检验卡方统计量的概率分布,红色阴影面积为显著性水平0.05,其对应的自由度为2时的卡方分布临界值为5.991;蓝色竖线是该检验得到的统计量的位置,统计量的值为59.2.由于检验统计量远大于临界值,拒绝原假设,表示不同满意度之间的人数分布有显著差异。_卡方检验有办法可视化吗

Java 使用正则表达式匹配淘口令_淘口令正则表达式-程序员宅基地

文章浏览阅读6.8k次,点赞4次,收藏8次。项目中被正则表达式的反斜线问题坑了几次了,今天恰好用到正则表达式的匹配,又遇到饭斜线的处理,记录一下。先对比其他语言和 Java 语言中反斜线,最后再给出淘口令匹配的案例。_淘口令正则表达式

手把手教你在 CentOS7 上部署Ngrok (踩坑&填坑)-程序员宅基地

文章浏览阅读1.1k次,点赞23次,收藏16次。ngrok是一款用Golang语言打造的开源的内网穿透软件,它可以帮助我们把内网的应用提供给外网用户访问。_ngrok

Qt之操作数据库(SQLite)_km.myqite.cn-程序员宅基地

文章浏览阅读3.9k次。SQLite简介SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如Tcl、C#、PHP、Java等,还有ODBC接口,同样比起Mysql、P_km.myqite.cn

推荐文章

热门文章

相关标签