UVA147 完全背包DP(坑爹精度题)
2015-11-23 22:57
519 查看
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 100,100, 50, 20,20, 10, and 5notesand5 notes and 2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up in 4 ways: 1 tex2html_wrap_inline25 20c, 2 tex2html_wrap_inline25 10c, 10c+2 tex2html_wrap_inline25 5c, and 4 tex2html_wrap_inline25 5c.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.202.00
0.00
Sample output
0.20 42.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]); } }
相关文章推荐
- django 运行python manage.py sqlall books 时报错 app has migration
- 高手详解SQL性能优化十条经验
- 中文标点的Unicode编码
- shared_ptr智能指针源码剖析
- 1085. Perfect Sequence (25)
- ***使用PHP实现文件上传和多文件上传
- jquery 操作表格实例
- 现在的大学生啊~[偶遇一奇葩应届java猿]
- js实现监听页面滚动实现图片延迟加载
- 1085. Perfect Sequence (25)
- objective-c中Category 类别、扩展 专题总结
- Java并发编程:Lock
- ZZULIOJ 1795 爱吃薯片的寒聚聚
- 1011. A+B和C (15)
- [转]response.getWriter().write()与out.print()的区别
- mac 使用git管理项目
- shared_ptr
- OC 类的创建及初始化方法
- Android开源项目第五篇——优秀个人和团体篇
- 小学四则运算APP 第一个冲刺阶段 第五天