Page 5 of 5

Posted: Sat Oct 20, 2007 5:36 pm
by Jan
malloc() declares memory but not initializes it. So, you must initialize y[0] before using it. Hope it helps.

Posted: Tue Oct 23, 2007 5:58 pm
by amine.hamdaoui
I did it, but it still doesn't work WA. Do you have any others ideas?

Re: 545

Posted: Thu Nov 06, 2008 11:05 am
by DD
amine.hamdaoui wrote: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;
}
I would recommand you to use interget to substitute double and perform exact calculation, since it maybe lost precison due to the using of double.

P.S. After two times W.A. by using the formula of 474, I decided to use exact calculation by interger and got A.C. finally. :D

Re: 545

Posted: Wed Jul 13, 2011 7:02 pm
by plamplam
I solved both 545 and 474 without log or log10 or pow or bigint. For 474, after you calculate the result, use the following snippet to output your result.
cout << showpoint << setprecision(4) << result;
The correct output for 6 is 1.562e-2 and not 1.563e-2 for 474. This is because the number is not rounded in this problem.

For 545, I got Wrong Answer thrice before I got Accepted. After I got Accepted, I thought I would compare the output of my programs and I wanted to post here some special cases, but guess what? The two outputs incisively matched on codeblocks. If you want to get accepted then one hint (I got accepted after adding 3 lines):

Consider the numbers 1.11450, 1.11550, 1.11650 and 1.11650.
Say x = 1.11450. Now if you print x with %0.3lf then the outputs for the four numbers will be:
1.115, 1.115, 1.117 and 1.117
Modify your code so that the output for these four numbers are instead:
1.115, 1.116, 1.117 and 1.118

Even after this modification, all the values from 1 to 9000 still remain unchanged(at least on my compiler) but for some eerie reason, the online judge doesn't accept without this rounding alteration.
This should help you :)

Re: 545

Posted: Mon Jun 11, 2012 2:09 pm
by xander7b
I got AC after replacing long double with double ! Used log10, pow and cin<<fixed and cin.precision(3) cin.precision(0)

Re: 545

Posted: Tue Dec 04, 2012 6:21 am
by achan8501
I honestly do not know what's wrong with my code. I used the square and double method, which worked perfectly well on 474, and is failing hard here. Eventually I took the suggestion of using BigInt, and got it accepted. I still have no idea what's wrong though, since both code gives the same output for all 9000 values.

Re: 545 - Heads

Posted: Thu Nov 13, 2014 6:15 pm
by lighted
Dominik Michniewski wrote:try to use log2() instead of log10() .... log2() means log(), I think .....

I remember, that it was difference in rounding ....

Dominik Michniewski
Got accepted with log10() and pow() in 0.015. There is no need in BigInt. :)

Re: 545 - Heads

Posted: Thu Aug 18, 2016 8:40 am
by metaphysis
The format of Sample Input is wrong, there is no r in first line.