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

tobat
New poster
Posts: 2
Joined: Mon Apr 27, 2009 3:17 pm

Re: why wa 147

Post by tobat »

It's accepted!
Last edited by tobat on Mon Apr 27, 2009 4:57 pm, edited 1 time in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: why wa 147

Post by mf »

Why wa
Can you read???

You made exactly the same mistake as almost everyone who posted here about their WA.

In short, to illustrate what it is, consider the following C/C++ boolean expressions:

Code: Select all

(int)(0.29 * 100) == 28
(int)(0.57 * 100) == 56
(int)(0.58 * 100) == 57
(int)(1.13 * 100) == 112
(int)(1.14 * 100) == 113
(int)(1.15 * 100) == 114
...
Here's the bummer: they all evaluate to true. You didn't see that coming, did you?

I suggest you read this article and this paper if you're curious why.
tobat
New poster
Posts: 2
Joined: Mon Apr 27, 2009 3:17 pm

Re: why wa 147

Post by tobat »

Thank you very much!
I'm so careless!
now I get AC,I will be careful next.
Thanks again.
fushar
New poster
Posts: 26
Joined: Fri Apr 03, 2009 12:09 pm
Location: Indonesia
Contact:

Re: why wa 147

Post by fushar »

I didn't use any floating point in this problem. To read the input, just type:

Code: Select all

scanf("%d.%d", &note, &coin);
It's so simple right?
Taman
New poster
Posts: 32
Joined: Sun Oct 11, 2009 8:59 pm
Location: Southeast University

Re: 147 ,WA

Post by Taman »

Thanks to Jan vai for his sample cases :)
Last edited by Taman on Mon Nov 29, 2010 9:54 am, edited 1 time in total.
Taman
New poster
Posts: 32
Joined: Sun Oct 11, 2009 8:59 pm
Location: Southeast University

Re: 147 __int64 can't hold big results.Please help

Post by Taman »

@Newton: Hope that I am too late. You have solved the problem btt.:)
check these inputs :
0.11
0.12
0.01


And the title of this thread is wrong:)
long long is enough for this problem. :) @ least I got acc using %lld ;)
seraph
New poster
Posts: 9
Joined: Tue Dec 15, 2009 4:18 pm

Re: 147 __int64 can't hold big results.Please help

Post by seraph »

i know why your code is WA :
your code

Code: Select all

printf("%6.2f%17llu\n", input, ways[ans]);
should :

Code: Select all

printf("%6.2f%17llu\n", input[b]+eps[/b], ways[ans]);
only thats, n you will AC :D :D :D
yan yan
New poster
Posts: 13
Joined: Thu May 13, 2010 4:16 pm
Location: Viet Nam
Contact:

Re: 147 ,WA

Post by yan yan »

everybody please help me :oops: , i don't understand why it's wrong..... :(

Code: Select all

removed after AC
@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

147 how to calculate coin change?

Post by @mjad »

please any body help me.
give me an example of coin change made up.
md_yusuf
New poster
Posts: 9
Joined: Fri Jun 25, 2010 11:09 pm

Re: 147 __int64 can't hold big results.Please help

Post by md_yusuf »

plz help me.. why wa..

Code: Select all

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

unsigned long long a[50000];

int main()
{
	unsigned long long i,j;
	int coin[]={5,10,20,50,100,200,500,1000,2000,5000,10000};
	a[0]=1;
	for(i=0;i<11;i++)
	{
		for(j=0;j<=30000;j++)
			a[j+coin[i]]+=a[j];
	}
	double n;
	while(1)
	{
		scanf("%lf",&n);
		int m;
		m=n*100;
		if(m==0)
			break;
		printf("%6.2lf%17llu\n",n,a[m]);
	}
}

i have check answer in uvatoolkit i think i have problem in output plz help me.
plz help im getting frustrated ....
sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 147 __int64 can't hold big results.Please help

Post by sazzadcsedu »

Rather than doing-
m= (n* 100), do this:
m = (int) (n * 100 + 0.5) to avoid floating point error.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
shamsacm
New poster
Posts: 6
Joined: Sat May 07, 2011 12:45 pm

Re: 147 __int64 can't hold big results.Please help

Post by shamsacm »

For floating point error

Input two integer number
Example

Code: Select all

scanf("%d.%d",&d,&c);
amount = d*100 + c;
shamsacm
New poster
Posts: 6
Joined: Sat May 07, 2011 12:45 pm

Re: 147 __int64 can't hold big results.Please help

Post by shamsacm »

Pls replace your code

Use integer not floating point

Code: Select all

 //scanf("%lf",&n);
     scanf("%d.%d",&d,&c);
      int m;
      //m=n*100;
      m = d*100+c;
      if(m==0)
         break;
      //printf("%6.2lf%17llu\n",n,a[m]);
      printf("%3d.%.2d%17llu\n",d,c,a[m]);
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

147 - Dollars

Post by @ce »

Getting WA....plzz help...any testcase

Code: Select all

AC
Last edited by @ce on Tue Jan 01, 2013 10:31 am, edited 1 time in total.
-@ce
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 147 - Dollars

Post by brianfry713 »

Input:

Code: Select all

0.30
0.00
AC output:

Code: Select all

  0.30                6
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 1 (100-199)”