107 - The Cat in the Hat
Moderator: Board moderators
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:
The correct output is:
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
Code: Select all
121 3367
-
- New poster
- Posts: 2
- Joined: Tue Jul 09, 2002 10:36 am
107 - The Cat in the Hat
///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;
}
}
}
}
}
#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;
}
}
}
}
}
-
- New poster
- Posts: 17
- Joined: Wed Jul 17, 2002 5:00 pm
WA :107 why??
@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
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
-
- New poster
- Posts: 17
- Joined: Wed Jul 17, 2002 5:00 pm
who can give some sample input and sample output for 107
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.
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.