147 - Dollars
Moderator: Board moderators
-
- Experienced poster
- Posts: 106
- Joined: Thu Jan 29, 2004 12:07 pm
- Location: Bangladesh
- Contact:
10000 ! You dont need an array that big. 6002 or 6001 would've done the trick. When I coded this , also used 6000 in the beginning. When I gave 300.00 for test, It crashed in my computer. So I knew what was wrong. Its strange that your previous program did not crash or show some msg of illegal operations for input larger than 300.00. Another strange thing is, for mistakes like these, you are supposed to get RTE from online-judge, not WA. I think this can be explained if the lower level details of the compiler and/or OS is known.
147 WA, output?
For this problem i generate table, is my output right(not formatted here)?(but i get WA, does only formatting cause WA)
0.05 1
0.45 9
3.95 2492
16.00 938319
125.00 228222517456
299.95 171788022101831
300.00 174088264125464
Also i have did another problem(160), but i get WA too.
http://acm.uva.es/board/viewtopic.php?t ... c09ad8f083
0.05 1
0.45 9
3.95 2492
16.00 938319
125.00 228222517456
299.95 171788022101831
300.00 174088264125464
Also i have did another problem(160), but i get WA too.
http://acm.uva.es/board/viewtopic.php?t ... c09ad8f083
why am I getting WA with my code. Well, I didnt divide the coins with 5 cents but it didnt caused a TLE. But I am getting WA . Can anyone check my code plz..
Code: Select all
cut off after AC
Last edited by Kallol on Wed Aug 30, 2006 7:25 am, edited 1 time in total.
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh
You have rounding errors, too.
Try to avoid doubles at all. You can read input, for example, in this way:
Try to avoid doubles at all. You can read input, for example, in this way:
Code: Select all
int dollars, cents;
scanf("%d.%d", &dollars, ¢s);
cents += 100 * dollars;
// output number of ways to make 'cents' cents
you dont have to initiate all array through...
make it declare as global...
Taht will make just u want all zero...
there may be enough reason for wrong anwer...
to avoid wa i take input as string...
removed the . (decimal point) to get integer....
the range goes to long long...
it is safe to avoid any floating point...
hope u can make it...
make it declare as global...
Taht will make just u want all zero...
there may be enough reason for wrong anwer...
to avoid wa i take input as string...
removed the . (decimal point) to get integer....
the range goes to long long...
it is safe to avoid any floating point...
hope u can make it...
-
- New poster
- Posts: 9
- Joined: Thu Sep 15, 2005 11:35 pm
- Location: dhaka
147 runtime error
what is the problem with this code. i am getting runtime error
Code: Select all
#include<iostream>
#include<cstdio>
#define MAX 10001
using namespace std;
int coins[] ={10000,5000,2000,1000,500,200,100,50,20,10,5};
unsigned long numOfChanges[MAX];
int main()
{
int numOfCoins =11;
int chngs=0;
numOfChanges[0]=numOfChanges[1]=numOfChanges[2]=numOfChanges[3]=numOfChanges[4]=1;
for(int i=0;i<numOfCoins;i++)
{
chngs = coins[i];
for(int j =chngs;j<MAX;j++)
{
numOfChanges[j] += numOfChanges[j-chngs];
}
}
double input;
while(scanf("%lf",&input)==1)
{
int data =(int)(input*100);
if(data==0)
{
break;
}
printf("%5.2lf%12lu\n",input, numOfChanges[data]);
}
return 0;
}
Hi.
The cause of Runtime Error in your case is invalid use of array.
Input range is 0.00-300.00, and your code handle :
But, you define MAX 10001. If the code tries to read over numOfChanges[10001], returns runtime error.
After fixed it, you'll avoid Runtime Error, but get WA.
To avoid WA, it's better to read existing thread
ex. http://online-judge.uva.es/board/viewto ... hlight=147
Best regards.
The cause of Runtime Error in your case is invalid use of array.
Input range is 0.00-300.00, and your code handle :
Code: Select all
int data =(int)(input*100);
After fixed it, you'll avoid Runtime Error, but get WA.
To avoid WA, it's better to read existing thread

ex. http://online-judge.uva.es/board/viewto ... hlight=147
Best regards.
I'm getting RE (invalid memory refrence):
if it's because if this line:
I used many methods but get WA
please explain it for me here don't send link .I read all the thread about147 but don't undrestand how to solve my problem.
please help.It's realy annoying me.
Code: Select all
#include<iostream>
#include<stdio.h>
using namespace std;
int a[6001][8],sum[6001][8],value[8]={1,2,4,10,20,40,100,200};
void main(){
int i,j,x,ans,dolor;
for(i=0;i<6001;i++)
sum[i][0]=a[i][0]=1;
for(i=0;i<6001;i++)
for(j=1;j<8;j++){
if(i<value[j]){
a[i][j]=0;
sum[i][j]=sum[i][j-1];
continue;
}
if(i==value[j]){
a[i][j]=1;
sum[i][j]=sum[i][j-1]+1;
continue;
}
ans=0;
x=i-value[j];
while(x>=0){
ans+=sum[x][j-1];
x-=value[j];
}
a[i][j]=ans;
sum[i][j]=sum[i][j-1]+ans;
}
float f;
scanf("%d.%d",&dolor,&x);
f=dolor+float(x)*0.01;
while(f!=0.0){
x+=dolor*100;
x/=5;
//cout.width(6);
//cout.precision(2);
//cout <<ios::fixed<<f;
printf("%6.2f",f);
cout.width(17);
cout <<sum[x][7]<< endl;
scanf("%d.%d",&dolor,&x);
f=dolor+x*0.01;
}
}
then how can I read input that I don't get WAscanf("%d.%d",&dolor,&x);
I used many methods but get WA
please explain it for me here don't send link .I read all the thread about147 but don't undrestand how to solve my problem.
please help.It's realy annoying me.

Hi, farzane.
First of all, read problem again, then you'll found this description.
And, the output may be very large value.
For example,
So, you should take care enough about the type of the variable.
By the way, I used scanf("%lf\n", &input);
Double type is convenient for this problem.
Best regards.
First of all, read problem again, then you'll found this description.
But, you wrote only 8 kinds of coins.New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins.
And, the output may be very large value.
For example,
Code: Select all
20.00 2886726
30.00 25473024
40.00 133337896
300.00 181490736388615
100.00 47580509178
By the way, I used scanf("%lf\n", &input);
Double type is convenient for this problem.
Best regards.
147-A problem with Pascal
here is my code and I'm getting wrong answer> why?
*************************************************************
program dollars;
const max=6000;
a:array[1..11] of integer=(2000,1000,400,200,100,40,20,10,4,2,1);
type m1=array[0..max] of int64;
var truc:m1;
procedure solve;
var j,t:integer;
u:real;
s:string;
begin
fillchar(truc,sizeof(truc),0);
truc[0]:=1;
for t:=1 to 11 do
for j:=0 to 6000 do
if truc[j]>0 then
if j+a[t]<=6000 then inc(truc[j+a[t]],truc[j]);
end;
procedure output(p:integer);
var j,t:integer;
i,u:real;
s:string;
d1,d2:integer;
begin
i:=p/20;
str(i:0:2,s);
d1:=length(s);
for j:=1 to 6-d1 do write(#32);
write(i:0:2);
str(truc[p],s);
d2:=length(s);
for j:=1 to 23-d2-6 do write(#32);
write(truc[p]);
end;
procedure process;
var i:real;
p:longint;
begin
solve;
readln(i);
repeat
output(trunc(i*20));
readln(i);
if i=0 then break else
writeln;
until false;
end;
BEGIN
process;
END.
*********************************************************
*************************************************************
program dollars;
const max=6000;
a:array[1..11] of integer=(2000,1000,400,200,100,40,20,10,4,2,1);
type m1=array[0..max] of int64;
var truc:m1;
procedure solve;
var j,t:integer;
u:real;
s:string;
begin
fillchar(truc,sizeof(truc),0);
truc[0]:=1;
for t:=1 to 11 do
for j:=0 to 6000 do
if truc[j]>0 then
if j+a[t]<=6000 then inc(truc[j+a[t]],truc[j]);
end;
procedure output(p:integer);
var j,t:integer;
i,u:real;
s:string;
d1,d2:integer;
begin
i:=p/20;
str(i:0:2,s);
d1:=length(s);
for j:=1 to 6-d1 do write(#32);
write(i:0:2);
str(truc[p],s);
d2:=length(s);
for j:=1 to 23-d2-6 do write(#32);
write(truc[p]);
end;
procedure process;
var i:real;
p:longint;
begin
solve;
readln(i);
repeat
output(trunc(i*20));
readln(i);
if i=0 then break else
writeln;
until false;
end;
BEGIN
process;
END.
*********************************************************
-
- New poster
- Posts: 5
- Joined: Fri Jun 30, 2006 10:02 pm
147 TLE ...??
here is my code... its giving TLE on submitting .. can any body help me..
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int coins[11]={5,10,20,50,100,200,500,1000,2000,5000,10000};
double u;
while(cin>>u&&u!=0)
{
int n=(int)(u*100);
long long d[30001];
d[0]=1;
int i,j;
for(i=1;i<=n;i++)
d=0;
for(i=0;i<11;i++)
{int c=coins;
for(j=c;j<=n;j++)
d[j]+=d[j-c];
}
printf("%7.2f%17lld\n",u,d[n]);
}
return 0;
}
I ve gone thru previous posts on 147 and find the same algo in all the
posts? so how can make it more effiently..??
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int coins[11]={5,10,20,50,100,200,500,1000,2000,5000,10000};
double u;
while(cin>>u&&u!=0)
{
int n=(int)(u*100);
long long d[30001];
d[0]=1;
int i,j;
for(i=1;i<=n;i++)
d=0;
for(i=0;i<11;i++)
{int c=coins;
for(j=c;j<=n;j++)
d[j]+=d[j-c];
}
printf("%7.2f%17lld\n",u,d[n]);
}
return 0;
}
I ve gone thru previous posts on 147 and find the same algo in all the
posts? so how can make it more effiently..??
You need to see previous posts more carefully
http://online-judge.uva.es/board/viewtopic.php?t=7535
Don't open a new thread if there is one already.. just use old one to post..
http://online-judge.uva.es/board/viewtopic.php?t=7535
Don't open a new thread if there is one already.. just use old one to post..