107 - The Cat in the Hat

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

Moderator: Board moderators

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard »

what about "1 100" ?
Archangel
New poster
Posts: 29
Joined: Wed Jun 26, 2002 9:00 am

Post by Archangel »

I had rewrote my program to let the output be "0 n" when any input of the form "1 n", but I still got wrong answer... :cry:
Did I still miss something?...Thanks!!
Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

Post by Revenger »

Picard write:
what about "1 100" ?
May be I am wrong, but ...
  • 1.The smallest cats have a heigth one, i.e. 1
  • 2.If Initial cat have a heigth one then there is only one cat
So I think, that there is no a such test
Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

Post by Revenger »

How can I get floating point operation error? If there are very big numbers in input then I really get floating point operation error. But what should I do in this case? Can you help me?
Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

Post by Revenger »

But there is a such test in input :(
What should I output?
Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard »

you are right. "1 100" is invalid. but there is a "1 1" in the judge's input, and there is a "2 1" too (which probably fails Archangel's solution).
Archangel
New poster
Posts: 29
Joined: Wed Jun 26, 2002 9:00 am

Post by Archangel »

I modified my code again...to let the output of "2 1" to be "1 3" and "1 1" to be "0 1",but still wrong answer again...>.<
Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

Post by Revenger »

Hi, Archangel!

It's very strange that your program gets WA. I have found error in my program in test "2 1" Try this test:

Code: Select all

1024 243
The correct output is:

Code: Select all

121 3367
Archangel
New poster
Posts: 29
Joined: Wed Jun 26, 2002 9:00 am

Post by Archangel »

Thank you~^^...but for the input "1024 243", my program gave me the right answer..."121 3367".

Will the input number out of the range of "unsigned Integer" be possible(21474836648~-21474836647)?? (because I declear my variable as Integer type)
10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

I think nope.

I just declare the variables to be int and it's OK. :D
limon limon
New poster
Posts: 2
Joined: Tue Jul 09, 2002 10:36 am

107 - The Cat in the Hat

Post by limon limon »

///this code give tlme limit exceeds error




#include<stdio.h>
#include<iostream.h>

#include<math.h>




void main()
{
unsigned long n,h,f,x=1,hi,nw,test,total,power,stack,count;
float p,nwf,hif;






count=-1;
for(;x==1; ){
f=0;
count++;
scanf("%lu%lu",&h,&n) ;

test=1;
if(n==0&&h==0)
x=0;
else
{
while(test==1)
{
f++;
p=f;

nwf=pow(n,1.0/p);
//hif=pow(h,1.0/p);

nw=nwf;

if(nwf-nw>0.5)
nw++;

hi=nw+1;



if(pow(nw,f)==n)
if (pow(hi,f)==h)
{

total=0;

stack=n;
for(power=0;power<f;power++)
{
total=total+pow(nw,power);

stack=stack+h*pow(nw,power);
h=h/hi;


}

if(count>0)
cout<<"\n";
cout<<total<<" "<<stack;



test=0;
}







}



}


}

}
galois_godel
New poster
Posts: 17
Joined: Wed Jul 17, 2002 5:00 pm

WA :107 why??

Post by galois_godel »

@BEGIN_OF_SOURCE_CODE
program P107(input,output);

var h,num,n,k,freenum,sumheight:integer;
r,rnum:real;
function getn(h,num:integer):integer;
var
i:integer;
c:real;
begin
if (h-num)=1 then
begin
getn:=num;
exit;
end;
i:=1;
c:=ln(num)*ln(i+1)-ln(h)*ln(i);
while abs(c)>0.00000001 do
begin
i:=i+1;
c:=ln(num)*ln(i+1)-ln(h)*ln(i);
end;
getn:=i;
end;
begin
// Insert user code here
while not eof(input) do
begin
readln(h,num);
if (h=0)and(num=0)then break;
if h=1 then
writeln(1,' ',0)
else
begin
if num=1 then
begin
k:=round(ln(h)/ln(2));
writeln(k,' ',2*h-1);
end
else
begin
n:=getn(h,num);
r:=h;rnum:=num;
r:=r*(n+1)-rnum*n;
writeln((num-1)div(n-1),' ',r:0:0);
end;
end;
end;


end.
@END_OF_SOURCE_CODE
galois_godel
New poster
Posts: 17
Joined: Wed Jul 17, 2002 5:00 pm

who can give some sample input and sample output for 107

Post by galois_godel »

who can give some sample input and sample output for problem 107
because I am unable to know why my answer is wrong


program P107(input,output);

var h,num,n,k,freenum,sumheight:integer;
r,rnum:real;
function getn(h,num:integer):integer;
var
i:integer;
c:real;
begin
if (h-num)=1 then
begin
getn:=num;
exit;
end;
i:=1;
c:=ln(num)*ln(i+1)-ln(h)*ln(i);
while abs(c)>0.00000001 do
begin
i:=i+1;
c:=ln(num)*ln(i+1)-ln(h)*ln(i);
end;
getn:=i;
end;
begin
// Insert user code here
while not eof(input) do
begin
readln(h,num);
if (h=0)and(num=0)then break;
if h=1 then
writeln(1,' ',0)
else
begin
if num=1 then
begin
k:=round(ln(h)/ln(2));
writeln(k,' ',2*h-1);
end
else
begin
n:=getn(h,num);
r:=h;rnum:=num;
r:=r*(n+1)-rnum*n;
writeln((num-1)div(n-1),' ',r:0:0);
end;
end;
end;


end.
soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja »

Use this sample. :)
( This test case is not mine. )


Input

371293 248832
11 10
1 1
1048576 59049
0 0

Output

22621 1840825
1 21
0 1
29524 4017157
soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja »

Use this sample.
( This test case is not mine. )


Input

371293 248832
11 10
1 1
1048576 59049
0 0

Output

22621 1840825
1 21
0 1
29524 4017157
Post Reply

Return to “Volume 1 (100-199)”