10683 - The decadary watch

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

Moderator: Board moderators

pipo
New poster
Posts: 47
Joined: Tue May 11, 2004 6:43 pm
Location: Republic of Korea

Post by pipo »

thanks krijger..

well.. i understood the first and second you told.

but.. i didnt understand the third...

what is difference between the third and casting in my code.. ?

what is 'avoiding small rounding error' you said ...

please show me examples about the small rounding error through source code.

thank you...
krijger
New poster
Posts: 39
Joined: Wed Jul 21, 2004 12:35 am

Post by krijger »

Code: Select all

#include<stdio.h>
#include<math.h>

int main() {
	for(int i=0;i<100;++i) {
		double val=sqrt(double(i))*sqrt(double(i));
		if(i!=(int)val) printf("%3d: %24.20lf %3d %3d\n",i,val,(int)val,(int)(val+1e-10));
	}
}
Obviously (int)val should be the same as i, but sometimes it isn't. If you use (int)(val+1e-10) everything goes well. Try it, you'll see.
Note that this method is by no means exact. The idea is that if something is only a very little less than a integer number, it was probably a rounding error, so we should use that integer number instead of the one far below it.
Also note that you have the same problem when checking for equality,lower/greater than, etc. Therefore I use this for floating point testing:

Code: Select all

#define ABS(a) ((a)<0)?-(a):(a))
#define EPS 1e-10
inline bool lt(dbl a,dbl b) { return a<b-EPS; }
inline bool le(dbl a,dbl b) { return a<=b+EPS; }
inline bool gt(dbl a,dbl b) { return a>b+EPS; }
inline bool ge(dbl a,dbl b) { return a>=b-EPS; }
inline bool eq(dbl a,dbl b) { return ABS(a-b)<=EPS; }
inline bool ne(dbl a,dbl b) { return ABS(a-b)>EPS; }
(lt=lower than,le=lower equal,gt=greater than,ge=greater equal,eq=equal,ne=not equal)
pipo
New poster
Posts: 47
Joined: Tue May 11, 2004 6:43 pm
Location: Republic of Korea

Post by pipo »

krijger.. thank you for answer..

i finally got accepted.

its problem is precision you told the second case.

and additionally i got the round error..

it's very interesting of me.

thank you again.. :)
dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

10683-WA plz help

Post by dust_cover »

Hi can someone tell me what is the problem with my code?
I have read all the topics before but cannot fix it :(
Moreover i have used all integer type to get over precision error.

Code: Select all

removed after ACC
thnax in advance!
Last edited by dust_cover on Wed Oct 11, 2006 10:46 am, edited 1 time in total.
i wanna give it a try....
sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan »

Try to use double & floor

Try this input
01000000


ur output is
416667

mine in:
0416667
dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

thnx buddy

Post by dust_cover »

hi Sakhasan,

thnx for your quick reply. I fixed my code & finally got ACC. I am too much grateful to you :D
i wanna give it a try....
Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

Where's the bug?

Post by Mushfiqur Rahman »

I tried this problem for many times but got WA. I didn't found my bug.
Anybody help please. :oops: :oops:

Here is my code.

Code: Select all

Removed after AC.
Last edited by Mushfiqur Rahman on Thu Mar 01, 2007 1:30 pm, edited 1 time in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Try the cases

Input:

Code: Select all

11014944
00114416
16570432
Output:

Code: Select all

4596000
0081500
7063000
Hope these help.
Ami ekhono shopno dekhi...
HomePage
Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

Thanks for cordial HELP

Post by Mushfiqur Rahman »

Thanks for your cordial help and data set. The bug was in floating division.
I replaced it by integer division and got AC. Can u tell me how can i remove the problem given bellow ?

double temp ;
long a;

temp = 5184/86.4 ; // here temp = 60.000000

a = temp ; // here a will be 59, but why?
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

It is called precision error. Try reading the following thread
http://online-judge.uva.es/board/viewto ... 5&start=15
Hope it helps.

And don't forget to remove your code.
Ami ekhono shopno dekhi...
HomePage
Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

Thanks

Post by Mushfiqur Rahman »

Thanks for the given link. I think it will also help more preson.
arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 10683 - The Decadary Watch

Post by arifcsecu »

not so hard ...Integer Division is sufficient
long int h,m,s,c,tt;

while(gets(ch))
{
h=(ch[0]-'0')*10+(ch[1]-'0');
m=(ch[2]-'0')*10+(ch[3]-'0');
s=(ch[4]-'0')*10+(ch[5]-'0');
c=(ch[6]-'0')*10+(ch[7]-'0');
tt=((h*60+m)*60+s)*100+c;
tt=tt*125/108;

printf("%07ld\n",tt);
}
Try to catch fish rather than asking for some fishes.
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10683 - The Decadary Watch

Post by plamplam »

Goddamn it.....this thing pissed me off so freaking much....I still don't understand why the following code doesn't get Accepted.
Consider this:

Code: Select all

    for (; ;)
    {
        gets(str);
        if (feof(stdin)) break;
        .....
    }
This gets a straight wrong answer but If I replace it with:

Code: Select all

    while(gets(str))
    {
        ...
    }
It gets Accepted right away...any explanation for this? Thanks in advance.
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
Hithrow
New poster
Posts: 1
Joined: Tue Oct 25, 2011 1:57 pm

Re: 10683 - The Decadary Watch

Post by Hithrow »

plamplam wrote:Goddamn it.....this thing pissed me off so freaking much....I still don't understand why the following code doesn't get Accepted.
Consider this:

Code: Select all

    for (; ;)
    {
        gets(str);
        if (feof(stdin)) break;
        .....
    }
This gets a straight wrong answer but If I replace it with:

Code: Select all

    while(gets(str))
    {
        ...
    }
It gets Accepted right away...any explanation for this? Thanks in advance.
I don't know the reason why it is not accepted, but thanks for the code replaced itself. You've helped me a lot! cell phone spy
Last edited by Hithrow on Fri Jan 13, 2012 8:42 am, edited 1 time in total.
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10683 - The Decadary Watch

Post by plamplam »

Glad to help :)
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
Post Reply

Return to “Volume 106 (10600-10699)”