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

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

Post by mf »

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?
The problem statement is fine. It's always up to YOU to determine whether a problem needs bignums or not!
In this problem, the largest output is less than 2^48, so a 'long long' is sufficient.

The biggest problem with your code is that you may have rounding errors in this line:

Code: Select all

n = (int)(f/0.05);
On my computer your code doesn't even pass the sample input - it outputs 252 for input 2.00.

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

147 why WA????

Post by ranban282 »

code removed...
Last edited by ranban282 on Sat May 06, 2006 5:28 am, edited 1 time in total.

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

Post by serur »

What if

Code: Select all

printf("%6.2f%17llu\n",x,array[(long long)(x*20+0.5)][10]); 
?

yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

147 wa plz help...

Post by yogeshgo05 »

hi guys i m getting wa for 147...
i just dont no whether the formatting of o/p is proper or not....
here's my code ...

Code: Select all

code deleted got it accepted...	  

shihabrc
New poster
Posts: 49
Joined: Sun Sep 18, 2005 10:20 am
Location: CSE,BUET
Contact:

147. Strange.

Post by shihabrc »

While solving the problem i converted every coin and amount to multiple of 5c(by multiplying with 20). But i was getting WA. To my surprise when I changed the conversion code(as i found in one of the posts) from,

int money=(int) (amount*20) to

int money=(int) (amount*20+0.5) I got AC. can anyone explain why?

-Shihab
Shihab
CSE,BUET

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

Because 'amount' is a floating point type and multiplying by powers of 10 (or even adding them) doesn't work quite well for numbers that are represented as powers of 2 (or something like that).
Instead of 0.5 any small number would do, 0.000001, for instance. Casting to int discards everything after the decimal point (and it might be something like .999999999)

You can read about it in misof's article:
http://www.topcoder.com/tc?module=Stati ... egersReals

Either avoid using floating points (if possible) or be paranoid while using them.

There's Goldberg's paper on the topic that I never bothered reading completely (maybe I should):
http://docs.sun.com/source/806-3568/ncg_goldberg.html

You can test it yourself with something like this (it's Java, but you get the idea):

Code: Select all

public class Test {

	public static void main(String[] args) {
		double a = 0.0;
		for (int i = 0; i < 50; i++) {
			System.out.println(i + " " + (20 * a));
			a += 0.1;
		}
	}

}

SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

147 why tle??????????????

Post by SHAHADAT »

This my code.Whats wrong is here?Why tle????
Code has been removed>>>>
Last edited by SHAHADAT on Sun Jun 25, 2006 9:10 am, edited 1 time in total.

SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

why wa 147

Post by SHAHADAT »

here is my code.Why wa????
Please can any one give critical input output?????????

code ha been removed.............
Last edited by SHAHADAT on Sun Jun 25, 2006 9:02 am, edited 1 time in total.

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

you may devide each coins by 5
then

Code: Select all

int coin[11]={10000,5000,2000,1000,500,200,100,50,20,10,5}; 
becomes

Code: Select all

int coin[11]={2000,1000,400,200,100,40,20,10,4,2,1};
then you need less calculation.

the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

I dont know how you could NOT expect WA????
You just don't even match the sample cases given in the problem!!!!
v=12
Musn't it be
v=11
???

and more, if you take the input as double, you can have precision errors.... it can be done with only integers to calculate the Cents. and if you are to use double then have some rounding stuff like
n=(taka*100+1e-5);
Bye.
Istiaque Ahmed [the LA-Z-BOy]

SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

Post by SHAHADAT »

Thanks a lot la-Z-BOy,
I have done a silly mistake.Atlast It is accepted

SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

Post by SHAHADAT »

Thank's a lot emotional blind.
I have got it accepted......

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

147 ,WA

Post by Carunty »

I have got wrong answer for sereval times.I need some help.
I think it is a problem on the place of the output.
Thank you.
the code is remove because of accepted.
[/quote]
Last edited by Carunty on Mon Jul 17, 2006 1:02 am, edited 1 time in total.

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

Post by Carunty »

Any people can help me?

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

Post by Raiyan Kamal »

Code: Select all

long long a[6000][11]; int b[]={1,2,4,10,20,40,100,200,400,1000,2000};
take a careful look at this line, you've made a little mistake here. I corrected it and got PE.

Post Reply

Return to “Volume 1 (100-199)”