Euro Efficiency

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 12   Accepted Submission(s) : 3
Problem 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
 题解:题意就是给你一部分面值的硬币,让算出从1到100的每个值所需的最少硬币个数的和除以100,再找到最大的,完全背包背包放满;这道题wa到无奈,想着把面值的一部分弄成负的,然后都加100保证都是正的,然后就是完全背包了,谁知道还呆多循环几次。。。感觉一次就行了;在这背包容量够大
代码:
 #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(完全背包)的更多相关文章

  1. POJ 1252 Euro Efficiency(完全背包, 找零问题, 二次DP)

    Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...

  2. POJ 1252 Euro Efficiency ( 完全背包变形 && 物品重量为负 )

    题意 : 给出 6 枚硬币的面值,然后要求求出对于 1~100 要用所给硬币凑出这 100 个面值且要求所用的硬币数都是最少的,问你最后使用硬币的平均个数以及对于单个面值所用硬币的最大数. 分析 :  ...

  3. POJ Euro Efficiency 1252

    Euro Efficiency Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4109   Accepted: 1754 D ...

  4. POJ 1252 Euro Efficiency(最短路 完全背包)

    题意: 给定6个硬币的币值, 问组成1~100这些数最少要几个硬币, 比如给定1 2 5 10 20 50, 组成40 可以是 20 + 20, 也可以是 50 -10, 最少硬币是2个. 分析: 这 ...

  5. Euro Efficiency_完全背包

    Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...

  6. POJ 1252 Euro Efficiency

    背包 要么 BFS 意大利是说给你几个基本的货币,组成 1~100 所有货币,使用基本上的货币量以最小的. 出口 用法概率.和最大使用量. 能够BFS 有可能 . 只是记得数组开大点. 可能会出现 1 ...

  7. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  8. Poj 1276 Cash Machine 多重背包

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Des ...

  9. poj 1276 Cash Machine(多重背包)

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33444   Accepted: 12106 De ...

随机推荐

  1. Unix主机syslog配置

    将下面的内容附加到/etc/syslog.conf文件中(注意*和@之间是有空格的): *.* @ip 修改/etc/services文件中的syslog服务的端口号为上面提到的Syslog监听端口. ...

  2. 如何实现Linux下的U盘(USB Mass Storage)驱动

    如何实现Linux下的U盘(USB Mass Storage)驱动 版本:v0.7 How to Write Linux USB MSC (Mass Storage Class) Driver Cri ...

  3. Android仿微信图片上传,可以选择多张图片,缩放预览,拍照上传等

    仿照微信,朋友圈分享图片功能 .可以进行图片的多张选择,拍照添加图片,以及进行图片的预览,预览时可以进行缩放,并且可以删除选中状态的图片 .很不错的源码,大家有需要可以下载看看 . 微信 微信 微信 ...

  4. LoggingApplicationListener

    org.springframework.boot:spring-boot:1.3.0.M1 spring-boot-1.3.0.M1.jar package org.springframework.b ...

  5. hdu 5093 Battle ships 匈牙利 很巧妙的建图思路

    //这题逼我把匈牙利学了 之前一直很勤快敲网络流 而且不以为耻反以为荣 解:首先按行扫描编号,如果在同一块中(即可以相互攻击),那么将其标为相同的数组,对列也做同样的操作. 然后扫描整张图,如果行编号 ...

  6. diff函数(matlab)

    diff函数式用于求导数和差分的.无论是求导数还是差分,其原理是一样的. 这里简单介绍下其用法: 前后相邻元素之差 上下相邻行之差. 与diff(A,1,1)类似. 第三个参数为2时,则变为列差分运算 ...

  7. poj 1573 Robot Motion_模拟

    又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...

  8. Linux内核中常见内存分配函数(三)

    ioremap void * ioremap (unsigned long offset, unsigned long size) ioremap是一种更直接的内存“分配”方式,使用时直接指定物理起始 ...

  9. 使用 fastlane 实现 iOS 持续集成(转)

    http://www.cocoachina.com/ios/20150916/13433.html 简介 持续集成是个“一次配置长期受益”的工作.但很多小公司都没有.以前在做Windows开发配置感觉 ...

  10. BZOJ 1833 ZJOI2010 count 数字计数 数位DP

    题目大意:求[a,b]间全部的整数中0~9每一个数字出现了几次 令f[i]为i位数(算前导零)中每一个数出现的次数(一定是同样的,所以仅仅记录一个即可了) 有f[i]=f[i-1]*10+10^(i- ...