Page **1** of **5**

### 545 - Heads

Posted: **Mon Jan 07, 2002 8:56 pm**

by **..**

Can anyone tell me why do I get PE??

Code: Select all

```
int main()
{
int N, expo;
char start = 1;
fscanf (stdin,"%d",&N);
while(1) {
if (fscanf (stdin,"%d",&N) == EOF)
break;
if (start) start = 0;
else printf ("n");
printf ("2^-%d = %.3fE-%dn", ?,?,?); // Spoiler removed :)
}
return 1;
}
```

Posted: **Mon Jan 07, 2002 11:28 pm**

by **Ilham Kurnia**

try not to use

if (start) start = 0;

else printf("n");

Posted: **Tue Jan 08, 2002 7:19 am**

by **..**

Thanks for your reply, but this question is a multiple input question, so I add these 2 lines.

Posted: **Tue Jan 08, 2002 9:05 am**

by **Ilham Kurnia**

so, then, what about trying to print a line after every test case? there are occasions when the judge's output has an extra line...

(one more reason why they say not to worry when you get PE...)

<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-01-08 08:06 ]</font>

Posted: **Tue Jan 08, 2002 11:42 am**

by **..**

tried...but still PE......

I guess there is something wrong about the judge output.....

Anyway, thanks for your help~

### 545

Posted: **Mon Apr 08, 2002 8:28 am**

by **sjn**

program p545;

var

i,index,n:integer;

procedure solve;

var

temp:real;

i,count:integer;

begin

temp:=1;

count:=0;

for i:=1 to n do

begin

temp:=temp/2;

if temp<1

then begin

temp:=temp*10;

inc(count);

end;

end;

writeln (temp:0:3,'E-',count);

end;

begin

readln (index);

while not eof do

begin

read(n);

write('2^-',n,' = ');

solve;

end;

end.

Thanks in advance

### Hope it'll help

Posted: **Mon Apr 08, 2002 3:14 pm**

by **chang**

Pls check the output for input=6, output should be 1.563.

I also got WA before handling specially this input.

chang

### Re: Hope it'll help

Posted: **Mon Apr 08, 2002 3:28 pm**

by **sjn**

chang wrote:Pls check the output for input=6, output should be 1.563.

I also got WA before handling specially this input.

chang

to chang:

thank you for replying

but i have done what you said, my program output is right

and alse WA so.....MY GOD!

### 545 What's wrong in my program? (I get WA)

Posted: **Mon Aug 05, 2002 7:37 pm**

by **medv**

I think my program is correct, but I get WA. Help me, please.

(* @JUDGE_ID: 4406RA 545 PASCAL "Simple calculation" *)

program Heads_545;

var

c,n:integer;

res:extended;

begin

readln(n);

while (n > 0) do

begin

res := exp(-n * ln(2));

c := 0;

while (res < 1) do

begin

res := res * 10; Inc(c);

end;

writeln('2^-',n,' = ',res:0:3,'E-',c);

readln(n);

end;

end.

Posted: **Tue Aug 06, 2002 7:57 am**

by **Dominik Michniewski**

try to use log10() in place of log2() ....

it should be help

error was occur for n=5 and n=6 if I correct remember ...

good luck

### What answer is correct for n=5 and n = 6?

Posted: **Thu Aug 08, 2002 11:56 am**

by **medv**

My answers are:

2^-6 = 1.563E-2

2^-5 = 3.125E-2

Are the correct?

If your 545 is accepted, send it for me to

medv@roller.ukma.kiev.ua.

I tried a lot, but got WA. Help me, if you can.

Thank you.

Posted: **Thu Aug 08, 2002 12:16 pm**

by **Dominik Michniewski**

I got right anserw on my computer too ....

But when OJ compiles and executes my program rounding error (maybe) occured ... in your case is the same

try to change base of logarithm and should be OK

### Nothing helps me with 545!!!

Posted: **Fri Aug 09, 2002 8:28 pm**

by **medv**

O-o-o How I tires of it! I tried it either in Pascal and in C, changed logarithm base system, even write the program that finds the solution without log and exp - straightforward, even I did rounding withount ROUND function - nothing helped me. I got WA! HEEELP!

This is my last program :

(* @JUDGE_ID: 4406RA 545 PASCAL "Simple calculation" *)

program Heads_545;

var

i,c,n,ri:integer;

ii,res:extended;

begin

readln(n);

while (n > 0) do

begin

if (n = 1) then

begin

writeln('2^-1 = 5.000E-1'); readln(n); continue;

end;

res := 1;

for i:=1 to n do

res := res / 2.0;

c := 0;

while (res < 1) do

begin

res := res * 10; Inc(c);

end;

ii := trunc(res);

write('2^-',n,' = ',ii:0:0,'.');

res := (res - ii) * 1000;

ri := round(int(res));

if (frac(res) >= 0.5) then Inc(ri);

if (ri < 10) then write('00') else

if (ri < 100) then write('0');

writeln(ri,'E-',c);

readln(n);

end;

end.

### 545 - Please, give me smb correct solution

Posted: **Fri Oct 25, 2002 9:50 pm**

by **medv**

Hi, everybody!

I posted here earlier the same question, but I haven't accepted this problem yet. Please, if smb solved it, send it's solution to me to

medv@roller.ukma.kiev.ua. What is the trick?

I tried to send a lot of solutions:

1 Solution. I was told about errors at n=5 and n=6, so I wrote here the exact answers, but it didn't help.

program Heads_545;

var

c,n:integer;

res:extended;

begin

readln(n);

while (n > 0) do

begin

if (n = 5) then

begin

writeln('2^-5 = 3.125E-2');readln(n); continue;

end;

if (n = 6) then

begin

writeln('2^-6 = 1.563E-2');readln(n);continue;

end;

res := exp(-n * ln(2));

c := 0;

while (res < 1) do

begin

res := res * 10; Inc(c);

end;

writeln('2^-',n,' = ',res:0:3,'E-',c);

readln(n);

end;

end.

2 Solution (it's not mine, but it is also doesn't accepted)

program Heads_545;

var n,x,m:extended;

begin

while not eof do

begin

readln(n);

m := n*ln(2)/ln(10);

x := frac(m) - 1;

writeln('2^-',n:0:0,' = ',exp(-x*ln(10)):0:3,'E-', m-x :0:0 );

end;

end.

Regards,

Michael

### Multiple input

Posted: **Tue Oct 29, 2002 8:22 pm**

by **luizflip**

Did you write your program to work with multiple input?

I am having the same problem as you. I only get WA.