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

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到6个正数,可将其相反数存到7到12中
PS:G++下double输出为%.2f,C++下double输出为%.2lf
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int dp[];
int a[],t;
int main()
{
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
double ans=0.0;
int pos=-;
for(int i=;i<=;i++)
{
scanf("%d",&a[i]);
a[i+]=-a[i];
}
for(int i=;i<=;i++)
{
dp[i]=INF;
}
dp[]=;
for(int i=;i<=;i++)
{
if(a[i]>)
{
for(int j=a[i];j<=;j++)
{
dp[j]=min(dp[j],dp[j-a[i]]+);
}
}
else
{
for(int j=;j>=-a[i];j--)
{
dp[j+a[i]]=min(dp[j+a[i]],dp[j]+);
}
}
}
for(int i=;i<=;i++)
{
ans+=dp[i];
pos=max(pos,dp[i]);
}
printf("%.2f %d\n",ans/(100.0),pos);
}
return ;
}

POJ Euro Efficiency 1252的更多相关文章

  1. Euro Efficiency(完全背包)

    Euro Efficiency Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Tot ...

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

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

  3. POJ 1252 Euro Efficiency

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

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

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

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

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

  6. HOJ题目分类

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

  7. POJ 1252 DP

    题意:给你6个数.让你求出1~100范围内的数 最优情况下由这六个数加减几步得到. 输出平均值和最大值. 思路: 我就随便写了写,,,感觉自己的思路完全不对. 但是交上去 AC了!!! 我先当减法 不 ...

  8. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

随机推荐

  1. 2015百度之星初赛2 1005 序列变换(LIS变形)

    LIS(非严格):首先我想到了LIS.然而总认为有点不正确:每一个数先减去它的下标.防止以下的情况发生:(转载) 3 增加序列是1,2,2,2,3,这样求上升子序列是3.也就是要改动2个,可是中间的两 ...

  2. 蓝牙压力測试报抛android.os.TransactionTooLargeException异常分析总结

    1.从main日志中找到异常点,例如以下: 08-20 11:05:19.754 5023 5023 E AndroidRuntime: FATAL EXCEPTION: main 08-20 11: ...

  3. POJ1502 MPI Maelstrom Dijkstra

    题意 给出图,从点1出发,求到最后一个点的时间. 思路 单源最短路,没什么好说的.注意读入的时候的技巧. 代码 #include <cstdio> #include <cstring ...

  4. poj_1974,最长回文字串manacher

    时间复杂度为O(n),参考:http://bbs.dlut.edu.cn/bbstcon.php?board=Competition&gid=23474 #include<iostrea ...

  5. 131.lambda表达式小结

    C++ 11中的Lambda表达式用于定义并创建匿名的函数对象,以简化编程工作.Lambda的语法形式如下:[函数对象参数](操作符重载函数参数) mutable或exception声明->返回 ...

  6. Android5.0之后的页面切换动画

    Android5.0之后给我们开发者剩了好多的事情,为什么这么说呢?还记得刚开始的时候,Android里面的所有的动画都要我们开发者自己来写,现在不需要了,因为5.0之后自带了好多的动画,比如:按钮点 ...

  7. UVa 140 Bandwidth【枚举排列】

    题意:给出n个节点的图,和一个节点的排列,定义节点i的带宽b[i]为i和其相邻节点在排列中的最远的距离,所有的b[i]的最大值为这个图的带宽,给一个图,求出带宽最小的节点排列 看的紫书,紫书上说得很详 ...

  8. del_archivelog

    #!/usr/bin/env bash                          #  # INTRO : The script for delete physical standby app ...

  9. GoldenGate 1403错误解决方法

    OGG  oracle goldengate 1403错误解决方法 1. 错误描述WARNING OGG-01154 Oracle GoldenGate Delivery for Oracle, re ...

  10. 【BZOJ 1051】[HAOI2006]受欢迎的牛

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Tarjan算法强连通缩点 . 最后出度为0的点. 如果只有一个. 那么这个"大点"所包含的点的个数就是答案了. ...