474 - Heads / Tails Probability
Moderator: Board moderators
-
- New poster
- Posts: 31
- Joined: Sat Nov 17, 2001 2:00 am
- Contact:
I think I'm one of two users who had solved this using Pascal... Well, I used floating point error checking twice... But then again, it's not something special isn't it?
I don't know exactly why there are only very few who have solved P#474 using Pascal. But, one of the notorious problems when you're making a solution using Pascal is that you have to be careful when you're reading the input. I recall having to try more than 5 different ways of reading input before getting my solution accepted.
Try using the following for Problem #474:
while not eof do
begin readln(n); Solve_it(N); end;
It may or may not help you...
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2001-12-25 11:06 ]</font>
I don't know exactly why there are only very few who have solved P#474 using Pascal. But, one of the notorious problems when you're making a solution using Pascal is that you have to be careful when you're reading the input. I recall having to try more than 5 different ways of reading input before getting my solution accepted.
Try using the following for Problem #474:
while not eof do
begin readln(n); Solve_it(N); end;
It may or may not help you...
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2001-12-25 11:06 ]</font>
-
- New poster
- Posts: 35
- Joined: Sat Jan 05, 2002 2:00 am
- Contact:
But 2^-6 = 1.5625E-2!On 2001-12-13 18:35, wyvmak wrote:
add this special case to your program:
2^-6 = 1.562E-2
So, the right answer should be 2^-6 = 1.563E-2!
Hence there is a mistake in test!
I think the matter of fact it the difference in rounding in C and Pascal.
In C: 1.5625E-2approx1.562E-2
In Pascal: 1.5625E-2approx1.563E-2
So, all the rejected Pascal programs (including my one
![:smile:](./images/smilies/icon_smile.gif)
![:sad:](./images/smilies/icon_frown.gif)
-
- New poster
- Posts: 31
- Joined: Sat Nov 17, 2001 2:00 am
- Contact:
actually no...
When you round 0.015625 to 4 significant figures scientifically, you get 0.01562 instead of 0.01563.
There are 3 general rules for rounding:
(last digit means the (last digit + 1) in
dispute... so in the case above, it is 5)
1. If the last digit is greater than 5, then you round the previous digit up. If the last digit is less than 5, then you round it down.
2. If it is 5, you look at the following digit(s). If it is not equal to 0, then you round the previous digit up. Else, see the next rule.
3. Look at the previous digit. If it is an even number, then you round it down. If it is an odd number, then you round it up.
hope this helps.
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-01-06 14:24 ]</font>
When you round 0.015625 to 4 significant figures scientifically, you get 0.01562 instead of 0.01563.
There are 3 general rules for rounding:
(last digit means the (last digit + 1) in
dispute... so in the case above, it is 5)
1. If the last digit is greater than 5, then you round the previous digit up. If the last digit is less than 5, then you round it down.
2. If it is 5, you look at the following digit(s). If it is not equal to 0, then you round the previous digit up. Else, see the next rule.
3. Look at the previous digit. If it is an even number, then you round it down. If it is an odd number, then you round it up.
hope this helps.
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-01-06 14:24 ]</font>
-
- New poster
- Posts: 31
- Joined: Sat Nov 17, 2001 2:00 am
- Contact:
Something that pops up to my mind...
Try to round the immediate results... My code is like that. somehow it avoids the rounding error.
hey... suddenly I'm the only person who got it right using pascal... strange... last week I saw another one...
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-01-06 14:40 ]</font>
Try to round the immediate results... My code is like that. somehow it avoids the rounding error.
hey... suddenly I'm the only person who got it right using pascal... strange... last week I saw another one...
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-01-06 14:40 ]</font>
-
- New poster
- Posts: 35
- Joined: Sat Jan 05, 2002 2:00 am
- Contact:
This rule seems strange. Colud you please tell us the author of this rule?On 2002-01-06 14:23, Ilham Kurnia wrote:
There are 3 general rules for rounding:
(last digit means the (last digit + 1) in
dispute... so in the case above, it is 5)
.................
3. Look at the previous digit. If it is an even number, then you round it down. If it is an odd number, then you round it up.
I used the following rules of rounding, which one can find in "Academic Press Dictionary of Science and Technology" (cf. http://www.harcourt.com/dictionary/def/ ... 69500.html):
According to this rule (x=5, b=10, x>(b-1)/2) 0,015625 approx 0,01563. So the right answer for the case n=6 should be 1.563E-2. This answer does not depend on the algorithm you use to solve this problem, sinse 2^{-6}=0,015625 (it is exact value).rounding Mathematics. the alteration of a radix representation of a real number, so that the true value of the number is represented to some desired accuracy. Also, rounding off. Any number whose radix representation is obtained in this manner is called a radix approximation. The following procedure is customarily followed: Let b be the base or radix used in the representation, and suppose the rightmost digit to be retained is followed by the digit x. If x <=(b - 1)/2, then the digits to the left of x are left unchanged, and x and the digits to its right are replaced with zeros. This is known as rounding down, since the result is less than or equal to the original number. If x > (b - 1)/2, then the rightmost digit to be retained is increased by 1 (carrying to the next place if necessary), and x and the digits to its right are replaced with zeros. This is known as rounding up, since the result is greater than or equal to the original number. Trailing zeros to the right of x are not written in the rounded number.
Since there are different rules of rounding, don't you think the better way is to eliminate the case n=6 from the test input data? The rounding is not the matter of the problem.
<font size=-1>[ This Message was edited by: Alexander Denisjuk on 2002-01-16 10:50 ]</font>
-
- New poster
- Posts: 31
- Joined: Sat Nov 17, 2001 2:00 am
- Contact:
Try the following:
http://wind.cc.whecn.edu/~mechalke/chap ... apter2.PDF
http://www.chem.tamu.edu/class/fyp/math ... sigfg.html
and many more
Furthermore, I've looked at several general chemistry and physics books, they suggest the same.
However, your rounding method is not wrong. I recall that there are two types of rounding: the mathematical rounding, which you described, and the scientific rounding which I described and used by the judge (maybe).
hmmm... that other solution in Pascal is back in the list...
Ilham
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-01-17 01:01 ]</font>
http://wind.cc.whecn.edu/~mechalke/chap ... apter2.PDF
http://www.chem.tamu.edu/class/fyp/math ... sigfg.html
and many more
Furthermore, I've looked at several general chemistry and physics books, they suggest the same.
However, your rounding method is not wrong. I recall that there are two types of rounding: the mathematical rounding, which you described, and the scientific rounding which I described and used by the judge (maybe).
hmmm... that other solution in Pascal is back in the list...
Ilham
<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-01-17 01:01 ]</font>
-
- New poster
- Posts: 35
- Joined: Sat Jan 05, 2002 2:00 am
- Contact:
-
- New poster
- Posts: 31
- Joined: Sat Nov 17, 2001 2:00 am
- Contact:
I want to share my experience to all of you:
I have a progam that can be accepted by judge,
when I run it in Unix, it gives me
2^-6 = 1.563e-2
when I run it in Linux, it gives me
2^-6 = 1.562e-2
I am really confused about this.......
Also, I find that my program will gives me like this:
2^-28738 = 10.000e-8652
2^-70777 = 10.000e-21307
Certainly, this is WRONG answer.....
It seems that the test case doesn't contain these cases.........
I have a progam that can be accepted by judge,
when I run it in Unix, it gives me
2^-6 = 1.563e-2
when I run it in Linux, it gives me
2^-6 = 1.562e-2
I am really confused about this.......
Also, I find that my program will gives me like this:
2^-28738 = 10.000e-8652
2^-70777 = 10.000e-21307
Certainly, this is WRONG answer.....
It seems that the test case doesn't contain these cases.........
-
- New poster
- Posts: 35
- Joined: Sat Jan 05, 2002 2:00 am
- Contact: