UVA147 完全背包DP(坑爹精度题)
来源:互联网 发布:大非农数据是什么意思 编辑:程序博客网 时间:2024/06/08 06:05
UVA147
这是一道类似UVA674的题,不过这次有50分,20分,10分和5分的硬币了,输入的时候有小数,留意到输入的只有两位小数,所以想直接都乘个100然后完全背包DP就完事了,然后输出的时候格式卡了好久…然后还是各种WA,后来搜了一下题解…居然是精度问题..一口血吐在屏幕上,注意用long long 和 int m = (int)(n*100+0.5)这两个点就好了,想知道大牛是怎么知道加个0.5的…
Description
New Zealand currency consists of
Input
Input will consist of a series of real numbers no greater than $300.00 each on a separate line. Each amount will be valid, that is will be a multiple of 5c. The file will be terminated by a line containing zero (0.00).
Output
Output will consist of a line for each of the amounts in the input, each line consisting of the amount of money (with two decimal places and right justified in a field of width 6), followed by the number of ways in which that amount may be made up, right justified in a field of width 17.
Sample input
0.20
2.00
0.00
Sample output
0.20 4
2.00 293
代码
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int coin[] = {5,10,20,50,100,200,500,1000,2000,5000,10000};long long dp[40000];int main(){ dp[0] = 1; for (int i = 0;i<11;i++) for(int j = coin[i];j<=30000;j++) dp[j]+=dp[j-coin[i]]; double n; while (scanf("%lf",&n)!=EOF) { if (n==0) break; int m = int(n * 100+0.5); printf("%6.2f%17lld\n",n,dp[m]); //printf("%d\n",dp[m]); }}
- UVA147 完全背包DP(坑爹精度题)
- uva147 - Dollars(完全背包)
- uva147 Dollars(完全背包方案)
- 完全背包问题UVA147
- uva147 - Dollars-------水题(精度注意)
- nyoj311 完全背包(dp)
- 完全背包(经典dp)
- 01背包、完全背包(DP)
- nyoj 311 完全背包(dp--完全背包)
- DP总结(1) 01背包 完全背包 多重背包
- csu1671 经营小卖部(DP 完全背包 好题)
- POJ 2063 Investment DP(完全背包)
- HDU 1114 1248(DP,完全背包)
- Piggy-Bank(dp完全背包问题)
- 寒冰王座(dp) 完全背包
- UVa 147 Dollars(DP完全背包)
- UVa 147 Dollars(DP完全背包)
- HDU 1114 (dp 完全背包)
- 关于tuple的创建中
- shared_ptr智能指针源码剖析
- 1085. Perfect Sequence (25)
- 中文标点的Unicode编码
- UITableView编辑
- UVA147 完全背包DP(坑爹精度题)
- HDU 1800-Flying to the Mars(trie树)
- IOS 委托和协议区别和联系
- ARM_s5pv210_arm_5(下)
- 昌大软院大神养成计划之网页设计之路第六天
- easyui datagrid 动态生成列
- GLSL着色语言的学习(二)光照模型
- java 静态方法和实例方法的区别
- vim文档设置