Re: 147 - Dollars
Posted: Tue Jan 01, 2013 10:31 am
@brianfry713....precision error....thanks...i got AC 

Code: Select all
0.30
12.35
2.25
3.55
9.90
199.90
288.45
278.42
285.65
300.00
122.40
148.90
43.68
123.90
0.00
Code: Select all
0.30 6
12.35 267166
2.25 388
3.55 1714
9.90 99998
199.90 7374160359543
288.45 131885563682391
278.42 0
285.65 121901430488365
300.00 181490736388615
122.40 196443681978
148.90 810222739797
43.68 0
123.90 214269035082
Code: Select all
#include<cstdio>
#include<iostream>
#include <cstring>
#define max 30000
using namespace std;
long long int c=30001,len,dp[12][max],coin[]= {5,10,20,50,100,
200,500,1000,2000,5000,10000};
long long int func(long long int i,long long int amount)
{
if(i>=len)
{
if(amount==0)
return 1;
else return 0;
}
if(dp[i][amount]!=-1)
return dp[i][amount];
long long int pro1=0;
if(amount-coin[i]>=0)
pro1=func(i,amount-coin[i]);
long long int pro2=func(i+1,amount);
return dp[i][amount]=pro1+pro2;
}
int main()
{
long long int a,b,d;
len=sizeof(coin)/8;
memset(dp,-1,sizeof(dp));
func(0,30001);
for (; (scanf("%lld.%lld",&c,&d)) ==2; )
{
if(c==0 && d==0)
return 0;
a=c*100+d;
printf("%3lld.%.2lld%17lld\n",c,d,func(0,a));
}
return 0 ;
}
Code: Select all
300.00
0.00
Code: Select all
300.00 181490736388615
Code: Select all
299.5
0.5
0.05
300
Code: Select all
299.05 176638443641346
0.05 1
0.05 1
300.00 181490736388615
Code: Select all
remove for AC ;-)
%17I64d is not a valid format specifier for gcc/g++. You may use %17lld instead.s25g5d4 wrote:Please help me. Don't know why get WA.
I'm afraid I don't understand what you're trying to say here. Are you saying you tried your program against invalid cases? Or that you're confident that the judge data contains invalid cases? Or something else?s25g5d4 wrote: Since the problem says each test case will be valid, I get the same output but invalid cases.
Does it matter?
Code: Select all
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ofstream out("output.txt");
long long table[30010];
int money[11]={5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000};
int main(int argc, char** argv) {
memset(table, 0, sizeof table);
table[0]=1;
for(int i=0; i<11; i++){
for(int j=money[i]; j<=30010; j++){
table[j]+=table[j-money[i]];
//out<<j<<endl;
}
}
float n;
cin>>n;
while(n!=0.00){
cout.width(6);
cout.precision(2);
cout << fixed << right << n;
cout.width(17);
n*=100;
cout<<right<<table[(int)n]<<endl;
cin>>n;
}
return 0;
}