545 - Heads

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

545 - Heads

Post by .. » Mon Jan 07, 2002 8:56 pm

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;
}
Last edited by .. on Tue Sep 23, 2003 4:49 pm, edited 2 times in total.

Ilham Kurnia
New poster
Posts: 31
Joined: Sat Nov 17, 2001 2:00 am
Contact:

Post by Ilham Kurnia » Mon Jan 07, 2002 11:28 pm

try not to use
if (start) start = 0;
else printf("n");

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. » Tue Jan 08, 2002 7:19 am

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

Ilham Kurnia
New poster
Posts: 31
Joined: Sat Nov 17, 2001 2:00 am
Contact:

Post by Ilham Kurnia » Tue Jan 08, 2002 9:05 am

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>

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. » Tue Jan 08, 2002 11:42 am

tried...but still PE......
I guess there is something wrong about the judge output.....
Anyway, thanks for your help~

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

545

Post by sjn » Mon Apr 08, 2002 8:28 am

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

chang
New poster
Posts: 16
Joined: Wed Jan 16, 2002 2:00 am

Hope it'll help

Post by chang » Mon Apr 08, 2002 3:14 pm

Pls check the output for input=6, output should be 1.563.
I also got WA before handling specially this input.

chang

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

Re: Hope it'll help

Post by sjn » Mon Apr 08, 2002 3:28 pm

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! :-? :-? :-?

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

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

Post by medv » Mon Aug 05, 2002 7:37 pm

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.

Dominik Michniewski
Guru
Posts: 832
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Tue Aug 06, 2002 7:57 am

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

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

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

Post by medv » Thu Aug 08, 2002 11:56 am

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.

Dominik Michniewski
Guru
Posts: 832
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Thu Aug 08, 2002 12:16 pm

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

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

Nothing helps me with 545!!!

Post by medv » Fri Aug 09, 2002 8:28 pm

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.

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

545 - Please, give me smb correct solution

Post by medv » Fri Oct 25, 2002 9:50 pm

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

luizflip
New poster
Posts: 2
Joined: Tue Oct 29, 2002 8:17 pm

Multiple input

Post by luizflip » Tue Oct 29, 2002 8:22 pm

Did you write your program to work with multiple input?

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

Post Reply

Return to “Volume 5 (500-599)”