545 - Heads
Moderator: Board moderators
-
- Experienced poster
- Posts: 131
- Joined: Sat Jul 17, 2004 4:09 am
- Location: Lima, Per
Please, help me. I don't know why I got WA.
Last edited by Antonio Ocampo on Mon Jan 31, 2005 3:14 am, edited 1 time in total.
Hi Antonio,
Firstly, you must catch correctly the input. See my post, for example.
Secondly, I have compared your output with mine for the 9000 possible cases and are the same!!! I have sent your code corrected and obtain WA!!!
I think that is a problem of small differences with the compilers (I have used Dev-C++).
Sorry, I can't help you much!!!
I'll try later, now I'm going to study. Next exam this monday
Bye.
Firstly, you must catch correctly the input. See my post, for example.
Secondly, I have compared your output with mine for the 9000 possible cases and are the same!!! I have sent your code corrected and obtain WA!!!
I think that is a problem of small differences with the compilers (I have used Dev-C++).
Sorry, I can't help you much!!!
I'll try later, now I'm going to study. Next exam this monday

Bye.
-
- Experienced poster
- Posts: 131
- Joined: Sat Jul 17, 2004 4:09 am
- Location: Lima, Per
Emilio wrote:
Hi Antonio,
Firstly, you must catch correctly the input. See my post, for example.
Secondly, I have compared your output with mine for the 9000 possible cases and are the same!!! I have sent your code corrected and obtain WA!!!
I think that is a problem of small differences with the compilers (I have used Dev-C++).
Well, I have used Dev-C++ too


Could someone tell me how to cath the input?? I don't know what to do

Thanks in advance
Your problem when you catch the input data is that you don't see if there is a blank line no time. You must do it as multiple input specification say. In the post where is my code you can see an example of this.
By another way, I used Dev-C++, and with this compiler I have compared your result and mine, and are the same, but the OJ say that no. And by this I think that the compiler of OJ obtain correct result for my code, but no for your code. I have used an approach different of yours.
By another way, I used Dev-C++, and with this compiler I have compared your result and mine, and are the same, but the OJ say that no. And by this I think that the compiler of OJ obtain correct result for my code, but no for your code. I have used an approach different of yours.
-
- Experienced poster
- Posts: 131
- Joined: Sat Jul 17, 2004 4:09 am
- Location: Lima, Per
I have corrected my code, but I still got WA. I don't know what's going on
My code is this

My code is this
Code: Select all
Deleted
Last edited by Antonio Ocampo on Fri May 06, 2005 12:28 am, edited 1 time in total.
-
- Experienced poster
- Posts: 131
- Joined: Sat Jul 17, 2004 4:09 am
- Location: Lima, Per
This is my corrected program, again.
But it doesn

Last edited by Antonio Ocampo on Fri May 06, 2005 12:29 am, edited 1 time in total.
First, you must change by
Second, you only must sum 0.0001 if the fourth decimal digit (after the point) is == 5
Third, you must change "s" by "n" in printf function.
Code: Select all
if (casos>1)
Code: Select all
if (casos>=1)
Third, you must change "s" by "n" in printf function.
-
- A great helper
- Posts: 281
- Joined: Tue Sep 10, 2002 5:14 am
- Location: Mountain View, CA, USA
- Contact:
nnahas, my code prints the same answers as the 150 that you posted, but it's still WA. Could you send me all of the 9000 answers? Here is my code. It's almost the same as the ones posted above.
I think this problem should require 7 decimal places, but have a special judge to allow plus or minus one in the last digit. Otherwise, in these problems you have to get lucky and make the same choices as the problem setter. :-(
Code: Select all
int main()
{
int N; cin >> N;
while( N-- )
{
int n; cin >> n;
int exp = ( int )ceil( log10( ( long double )2.0 ) * n );
long double mantissa = pow( 10.0, exp - log10( ( long double )2.0 ) * n );
printf( "2^%d = %.3LfE%d\n", -n, mantissa, -exp );
}
return 0;
}
If only I had as much free time as I did in college...
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
I am afraid I don't agree with you here.
For this problem it is quite possible to calculate the exact answers (using arbitrary precision calculus and rounding) and I think this is what the problemsetter had in mind. If you choose to use an approximation (using floating point calculus) you should be prepared to get (language and implementation specific) precision errors, like the ones you encounter. But then don't blame the problemsetter...
FYI:
My first program, using arbitrary precision and rounding, got AC at once in about 2 seconds.
My second program, using approximation, gets accepted in about 0.15 seconds, but I had to write several versions before all 9000 possible answers were exactly the same as the ones I calculated using my first program.
For this problem it is quite possible to calculate the exact answers (using arbitrary precision calculus and rounding) and I think this is what the problemsetter had in mind. If you choose to use an approximation (using floating point calculus) you should be prepared to get (language and implementation specific) precision errors, like the ones you encounter. But then don't blame the problemsetter...

FYI:
My first program, using arbitrary precision and rounding, got AC at once in about 2 seconds.
My second program, using approximation, gets accepted in about 0.15 seconds, but I had to write several versions before all 9000 possible answers were exactly the same as the ones I calculated using my first program.
Hello.
I have solved this problem using DP and Pascal.But 474 I solve using C++.
And I solve this one from first submission.
I think it is better to try this problem using Pascal,but 474 using C++.
Eduard.
I have solved this problem using DP and Pascal.But 474 I solve using C++.
And I solve this one from first submission.
I think it is better to try this problem using Pascal,but 474 using C++.
Eduard.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
About the arbitrary precision and rounding - it is true, you have to do that, although I had to manually round the numbers, couldn't use Java's Math.round()
I used BigInt (start with 1000...000) and if I converted first five digits into a double and rounded it with Math.round() it didn't work. When I used integers and rounded it with something like
if (s.charAt(4) > '4') tmp++;
, it worked.
Here are a few interesting cases:
Input:
Output:
EDIT: It was just rounding after all - arbitrary precision is NOT needed, I used doubles and kept them in [1.0,10.0), but manually rounded them (as described above). I am not sure why Math.round() approach wasn't working.
I used BigInt (start with 1000...000) and if I converted first five digits into a double and rounded it with Math.round() it didn't work. When I used integers and rounded it with something like
if (s.charAt(4) > '4') tmp++;
, it worked.
Here are a few interesting cases:
Input:
Code: Select all
3
287
669
4168
Code: Select all
2^-287 = 4.022E-87
2^-669 = 4.083E-202
2^-4168 = 2.028E-1255
-
- New poster
- Posts: 10
- Joined: Tue Aug 07, 2007 7:33 pm
Why do i get WA. I use exact calculation. I have tested my code for all the tests in this topic, and it match!!!!
Code: Select all
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j,r,n,*y,a;
double *x;
y = (int *) malloc(sizeof(int )*1000001);
x = (double *) malloc(sizeof(double)*1000001);
x[0] = 1;
y[0] = 0;
for(j=1 ; j<1000001 ; j++)
{
x[j] =x[j-1]/2.0;
if(x[j]<1)
{
x[j] *=10.0;
y[j]=y[j-1]+1;
}
else y[j]=y[j-1];
}
scanf("%d",&r);
for(i=1 ; i<=r ; i++)
{
scanf("%d",&n);
printf("2^-%d = %1.3fE-%d\n",n,x[n],y[n]);
}
return 0;
}
Last edited by amine.hamdaoui on Tue Oct 23, 2007 5:56 pm, edited 2 times in total.