Euro Efficiency(完全背包)
Euro Efficiency
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 12 Accepted Submission(s) : 3
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.
#include<stdio.h>
#include<string.h>
#define MAX(x,y)(x>y?x:y)
#define MIN(x,y)(x<y?x:y)
const int INF=0x3f3f3f3f;
const int MAXN=;//这个要比下面大100
int bag[MAXN];
int eur[];
int main(){
int T;
scanf("%d",&T);
while(T--){
int sum=,mx=,flot=;
for(int i=;i<;i++)scanf("%d",&eur[i]),eur[i+]=-eur[i];
memset(bag,INF,sizeof(bag));
bag[]=;
while(flot){//flot多循环几次。。。
flot=;
for(int k=;k<;k++)
for(int j=eur[k]+;j<=;j++){//开到200就wa
// bag[j]=MIN(bag[j],bag[j-eur[k]]+1);
if(bag[j-eur[k]]+<bag[j])bag[j]=bag[j-eur[k]]+,flot=;
}
}
for(int i=;i<=;i++){
// printf("%d ",bag[i+100]);
sum+=bag[i+];
mx=MAX(mx,bag[i+]);
}
printf("%.2f %d\n",sum/100.0,mx);
}
return ;
}
Euro Efficiency(完全背包)的更多相关文章
- POJ 1252 Euro Efficiency(完全背包, 找零问题, 二次DP)
Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...
- POJ 1252 Euro Efficiency ( 完全背包变形 && 物品重量为负 )
题意 : 给出 6 枚硬币的面值,然后要求求出对于 1~100 要用所给硬币凑出这 100 个面值且要求所用的硬币数都是最少的,问你最后使用硬币的平均个数以及对于单个面值所用硬币的最大数. 分析 : ...
- POJ Euro Efficiency 1252
Euro Efficiency Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4109 Accepted: 1754 D ...
- POJ 1252 Euro Efficiency(最短路 完全背包)
题意: 给定6个硬币的币值, 问组成1~100这些数最少要几个硬币, 比如给定1 2 5 10 20 50, 组成40 可以是 20 + 20, 也可以是 50 -10, 最少硬币是2个. 分析: 这 ...
- Euro Efficiency_完全背包
Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...
- POJ 1252 Euro Efficiency
背包 要么 BFS 意大利是说给你几个基本的货币,组成 1~100 所有货币,使用基本上的货币量以最小的. 出口 用法概率.和最大使用量. 能够BFS 有可能 . 只是记得数组开大点. 可能会出现 1 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- poj 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33444 Accepted: 12106 De ...
随机推荐
- MEMS陀螺仪(gyroscope)的工作原理
传统的陀螺仪主要是利用角动量守恒原理,因此它主要是一个不停转动的物体,它的转轴指向不随承载它的支架的旋转而变化. 但是MEMS陀螺仪(gyroscope)的工作原理不是这样的,因为要用微机械技术在硅片 ...
- Ruby小例子
1.ruby定义函数与执行函数案例 def fact(n) ) end end print fact() 结果: 24 2.一个小例子 words = [)] print "guess?\n ...
- MIN (Transact-SQL)【转】
MIN (Transact-SQL) 其他版本 SQL Server 2005 此主题尚未评级 - 评价此主题 返回表达式中的最小值. 后面可能跟随 OVER 子句. Transact-S ...
- Cocoapod安装使用
近期换工作.项目中推荐使用Cocoapod,把经常使用的第三方库增加到project中,大致说一下流程,标记一下. 第一步:安装 CocoaPods是跑在Ruby的软件,安装可能须要几分钟.打开你的终 ...
- Tsinghua dsa pa2
第一题,列车调度(train) 在这个题目中,模拟压栈出栈,同时判断调度方案是否可行. #include <cstdio> #include <cstring> #define ...
- 【Tarjan,LCA】【3-21个人赛】【problemD】
Problem D Time Limit : 6000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 《think in python》学习-7
think in python 7 迭代 对一个变量可以进行多次赋值 是合法的. 例如以下: bruce = 5 print bruce bruce = 7 print bruce 因为有了多重赋值 ...
- jQuery ZeroClipboard中Flash定位不准确的解决方案
转自波斯马,原文地址<jQuery ZeroClipboard中Flash定位不准确的解决方案> jQuery ZeroClipboard支持在多种浏览器中复制内容到剪贴板,IE.Fire ...
- JavaScript function函数种类(转)
转自:http://www.cnblogs.com/polk6/p/3284839.html JavaScript function函数种类 本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通 ...
- C# 5 break continue 球员成绩 彩票 选班长
二.新课: 1.break与continue. 这两个关键字一般放在循环的花括号里面使用. break--结束整个循环. continue--结束本次循环,进入下次循环. break的案例: ...