## 10683 - The decadary watch

Moderator: Board moderators

pipo
New poster
Posts: 47
Joined: Tue May 11, 2004 6:43 pm
Location: Republic of Korea
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

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

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

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

hi Sakhasan,

thnx for your quick reply. I fixed my code & finally got ACC. I am too much grateful to you
i wanna give it a try....

Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Contact:

### Where's the bug?

I tried this problem for many times but got WA. I didn't found my bug.

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
Contact:
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
Contact:

### Thanks for cordial HELP

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
Contact:
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
Contact:

### Thanks

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

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

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

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