147 - Dollars

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Carunty
New poster
Posts: 18
Joined: Sat Jul 08, 2006 2:40 am

Post by Carunty » Mon Jul 17, 2006 1:04 am

Thank you. I have got AC.

I just change the array size be a[10000][11];

why it is wrong before?

The question said that the maximun input is 300.00.
and i have test , my program work for all case less then 300.05

Hope you can answer me.

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal » Mon Jul 17, 2006 5:26 pm

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.

Carunty
New poster
Posts: 18
Joined: Sat Jul 08, 2006 2:40 am

Post by Carunty » Mon Jul 17, 2006 9:40 pm

thank you

nev4
New poster
Posts: 15
Joined: Sun Apr 30, 2006 10:19 am
Location: Lithuania

147 WA, output?

Post by nev4 » Wed Aug 16, 2006 9:22 am

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

User avatar
Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol » Wed Aug 30, 2006 6:31 am

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

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Wed Aug 30, 2006 6:54 am

You have rounding errors, too.

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, &cents);
cents += 100 * dollars;
// output number of ways to make 'cents' cents

User avatar
Tanu
Learning poster
Posts: 70
Joined: Sun May 29, 2005 12:46 pm
Location: Mars

Post by Tanu » Wed Aug 30, 2006 7:12 am

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...

User avatar
Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol » Wed Aug 30, 2006 7:25 am

Thnx I just got AC(P.E).
actually I didnt know that type of use of scanf.
Thanx mf
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh

opportunity
New poster
Posts: 9
Joined: Thu Sep 15, 2005 11:35 pm
Location: dhaka

147 runtime error

Post by opportunity » Thu Aug 31, 2006 1:20 am

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;
}

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Post by tan_Yui » Thu Aug 31, 2006 3:49 am

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 :

Code: Select all

int data =(int)(input*100);
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.

farzane
New poster
Posts: 26
Joined: Thu Jun 15, 2006 9:26 am

Post by farzane » Tue Sep 12, 2006 12:12 am

I'm getting RE (invalid memory refrence):

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;
	}
}
if it's because if this line:
scanf("%d.%d",&dolor,&x);
then how can I read input that I don't get WA
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. :(

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Post by tan_Yui » Tue Sep 12, 2006 4:52 pm

Hi, farzane.
First of all, read problem again, then you'll found this description.
New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins.
But, you wrote only 8 kinds of 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
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.

truongbom
New poster
Posts: 1
Joined: Fri Sep 22, 2006 8:28 am

147-A problem with Pascal

Post by truongbom » Fri Sep 22, 2006 8:34 am

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.
*********************************************************

Uttam Dwivedi
New poster
Posts: 5
Joined: Fri Jun 30, 2006 10:02 pm

147 TLE ...??

Post by Uttam Dwivedi » Mon Feb 12, 2007 10:38 pm

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..??

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Tue Feb 13, 2007 4:17 am

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..

Post Reply

Return to “Volume 1 (100-199)”