UVA 147 - Dollars
这道题要注意高精度误差,我这样做稍有一些麻烦,不如将面值放大成1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 2000再用整数计算,省去了我这个浮点误差(代码中的+0.1)的麻烦。
代码如下:
#include<stdio.h>
#include<string.h>
double n;
double chang[12] = { 0,0.05,0.1,0.2,0.5,1,2,5,10,20,50,100};
long long f[6000+10];
void solve()
{
double amount = 300.10;
memset(f,0,sizeof(f));
f[0] = 1;
for(int i = 1; i <= 11; i ++)
for(double j = chang[i]; j <= amount; j += 0.05)
f[(long long)(j/0.05+0.1)] += f[(long long)((j - chang[i])/0.05 +0.1)];
}
void input()
{
solve();
while(scanf("%lf",&n) == 1)
{
if(n == 0) break;
printf("%6.2f%17lld\n",n,f[(long long)(n/0.05 +0.1)]);
}
}
int main()
{
input();
return 0;
}