10683 - The decadary watch
Moderator: Board moderators
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...
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...
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));
}
}
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; }
-
- 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![:(](./images/smilies/icon_frown.gif)
Moreover i have used all integer type to get over precision error.
thnax in advance!
I have read all the topics before but cannot fix it
![:(](./images/smilies/icon_frown.gif)
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....
-
- 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![:D](./images/smilies/icon_biggrin.gif)
thnx for your quick reply. I fixed my code & finally got ACC. I am too much grateful to you
![:D](./images/smilies/icon_biggrin.gif)
i wanna give it a try....
-
- Learning poster
- Posts: 56
- Joined: Tue Jun 13, 2006 5:18 pm
- Location: (CSE, SUST) Sylhet, Bangladesh
- Contact:
Where's the bug?
I tried this problem for many times but got WA. I didn't found my bug.
Anybody help please.
Here is my code.
Anybody help please.
![:oops:](./images/smilies/icon_redface.gif)
![:oops:](./images/smilies/icon_redface.gif)
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.
Try the cases
Input:
Output:
Hope these help.
Input:
Code: Select all
11014944
00114416
16570432
Code: Select all
4596000
0081500
7063000
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- Learning poster
- Posts: 56
- Joined: Tue Jun 13, 2006 5:18 pm
- Location: (CSE, SUST) Sylhet, Bangladesh
- 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?
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?
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.
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
HomePage
-
- Learning poster
- Posts: 56
- Joined: Tue Jun 13, 2006 5:18 pm
- Location: (CSE, SUST) Sylhet, Bangladesh
- Contact:
Thanks
Thanks for the given link. I think it will also help more preson.
-
- 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);
}
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.
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:
This gets a straight wrong answer but If I replace it with:
It gets Accepted right away...any explanation for this? Thanks in advance.
Consider this:
Code: Select all
for (; ;)
{
gets(str);
if (feof(stdin)) break;
.....
}
Code: Select all
while(gets(str))
{
...
}
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
Re: 10683 - The Decadary Watch
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 spyplamplam 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:
This gets a straight wrong answer but If I replace it with:Code: Select all
for (; ;) { gets(str); if (feof(stdin)) break; ..... }
It gets Accepted right away...any explanation for this? Thanks in advance.Code: Select all
while(gets(str)) { ... }
Last edited by Hithrow on Fri Jan 13, 2012 8:42 am, edited 1 time in total.
Re: 10683 - The Decadary Watch
Glad to help ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson