Posted: Wed Jun 08, 2005 6:02 am
I got AC with unsigned long long.And I am not too sure how the judge feels about __int64.
I do see you have mixed cin/printf, but I don't understand why. I believe you have good reasons for doing so, otherwise its better to stick tocOsMo wrote:Code: Select all
#include <cstdio> #include <iostream>
I dont think you have read the problem description very well...Code: Select all
#define MAX_N 6000 #define M 11 using namespace std; int coins[]={1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 4000};
Dont actually need double, and if you do use double you can't do a == operation on floating point operands.Its best avoided, otherwise add some tolerance before doing so.Code: Select all
double input; cin>>input; if (input==0.00) break;
Code: Select all
#define EPS 1e-13
...
double input;
cin>>input;
if ( fabs(input) < EPS ) break;
?cOsMo wrote:Code: Select all
if (input<EPS) break;
should becOsMo wrote:Code: Select all
printf( "%6.2lf%17lld\n", input, ways[ n ] );
Code: Select all
printf( "%6.2lf%17llu\n", input, ways[ n ] );
Program should stop if input<EPS...Why did you put "?"cOsMo wrote:Code: Select all
if (input<EPS) break;
Do you understand why I told you to add EPSin the very first place?I hope you do.I suggested a way, since you deviated a bit, I was wondering why.cOsMo wrote:Code: Select all
if (input<EPS) break; ... Program should stop if input<EPS...Why did you put "?"
cOsMo wrote:Code: Select all
int coins[]={1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, [b]2000[/b]};
So I'll not have to go buy a pair of specs!You scared mecOsMo wrote: I think you did not read it very well.
Code: Select all
#include <cstdio>
...[snipped]
return 0;
}
My AC code is 23 lines long.And it is in simple C.I changed your code a bit and it got AC'ed in 0.045 sec, using as much as 64K mem.cOsMo wrote: Since everything in the input will be of a form 5*x you can divide everything by 5 and save memory and time.
Code: Select all
int dec, frac, n;
while( 2 == scanf("%d.%d",&dec, &frac) ) {
n = dec * 100 + frac;
if ( !n )
break;
/* Note I am indexing to n/5 th element here,
** to be consistent with your code,
** will land you with RTE otherwise
*/
printf("%6.2f%17llu\n",((float)n/100.0f),ways[n/5]);
}
Code: Select all
Deleted code...
Code: Select all
program dollars;
const
n = 11;
k = 30000;
c: array [1..n] of integer = ( 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000 );
var
b: array [1..k] of qword;
r: real;
i, j, m: longint;
begin
b[0]:= 1;
for i:= 1 to k do b[i]:= 0;
for i:= 1 to n do
for j:= c[i] to k do
b[j]:= b[j] + b[j-c[i]];
readln (r);
while r <> 0 do begin
m:= trunc (r * 100+0.000001);
writeln (r:6:2, b[m]:17);
readln (r);
end;
end.
Code: Select all
// 147 Dollars
#include <stdio.h>
#define MAXTOTAL 10000
long long nway[MAXTOTAL+1];
int coin[11] = { 2000,1000,400,200,100,40,20,10,4,2,1 };
int main() {
double f;
int i,j,n,v,c;
while (1) {
scanf("%lf", &f);
if (f == 0.00) break;
n = f/0.05;
for (i=0; i<=n; i++) nway[i] = 0;
v = 11;
nway[0] = 1;
for (i=0; i<v; i++) {
c = coin[i];
for (j=0; j<=n-c; j++)
nway[j+c] += nway[j];
}
wprintf(L"%6.2lf %17.lld\n", f, nway[n]);
}
return 0;
}
Code: Select all
n = f/0.05;
The problem statement is unclear. ex. starting from input about "50.00" my output becomes very big. But this is not a big integer problem, right?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).
Code: Select all
// 147 Dollars
#include <stdio.h>
#define MAXTOTAL 10000
long long nway[MAXTOTAL+1];
int coin[11] = { 2000,1000,400,200,100,40,20,10,4,2,1 };
int main() {
double f;
int i,j,n,v,c;
while (1) {
scanf("%lf", &f);
if (f == 0.00) break;
n = (int)(f/0.05);
for (i=0; i<=n; i++) nway[i] = 0;
v = 11;
nway[0] = 1;
for (i=0; i<v; i++) {
c = coin[i];
for (j=c; j<=n; j++)
nway[j] += nway[j-c];
}
printf("%.2lf %lld\n", f, nway[n]);
}
return 0;
}