Page 13 of 19

Good solution in 107 but get WA!!! What wrong in algo?

Posted: Mon Apr 05, 2004 11:39 am
by QulinXao
here good solution but WA what wrong:
get x y
where x==a^b (1) and y==(a-1)^b (2)
sheach b with this property: exp(ln(exp(ln(x)/b) -1)*b)==y
then out is:
((a-1)^b-1)/(a-1-1) and (a^(b+1)-(a-1)^(b+1))/(a-(a-1)) or same

(y-1)/(a-2) and a*x-(a-1)*y

[pascal]var x,y,a,b:int64;begin repeat
readln(x,y);
if(x=0)and(y=0)then break;
if x>1 then begin
b:=0;
repeat inc(b);
a:=round(exp(ln(x)/b));
until round(exp(ln(a-1)*b))=y;
end;
if x<3 then write(x-1)else write((Y-1)div(a-2));
writeln(' ',x*a-y*(a-1));
until 1=0;
end.[/pascal]

Posted: Mon Apr 12, 2004 11:06 am
by QulinXao
sorry to all cose I test on all test here and get some hint what was wrong in my "Good sol...",now I get acccepted 107 problem.
And what amazing the algo more simple then pred I post :o

107 Cat in the hat

Posted: Sat May 15, 2004 8:25 pm
by kec
I tried to solve 107 problem, but unfortunetlly I've got few TLE, when I change some of the varible types (to smaller - dword) I've got a WA. That is wrong ??? Please HELP ME.
[pascal]
program p107;
{$APPTYPE CONSOLE}
var
poziom: integer;
vn: integer;
wea,web: longword;
wya,wyb: longword;



function pwr(x,n: real): real;
begin
pwr:=exp(n*ln(x));
end;

function root(x,n: real): real;
begin
n:=1/n;
root:=exp(n*ln(x));
end;

function Findinhatcat(a,b: longword): longword;
var
x: longword;
begin
x:=1;
while (trunc(10000*(root(a,x)-1))<>trunc(10000*(root(b,x)))) and (x<100) do inc(x);

findinhatcat:=x;
vn:=round(root(b,x));
end;

function ilekotow(poz,n: integer): longword;
var
a: integer;
x: longword;
begin
x:=0;
for a:=0 to poz-1 do
x:=x+trunc(pwr(n,a));
ilekotow:=x;
end;

function wys(poz,n: integer): longword;
var
a: integer;
x: real;
ile: integer;
w: real;
begin
x:=0;
w:=wea*(1+n);
for a:=0 to poz do
begin
ile:=trunc(pwr(n,a));
w:=w/(n+1);
x:=x+ile*w;
end;
wys:=round(x);
end;

begin
readln(wea,web);
while (wea<>0) or (web<>0) do
begin
if (wea>1) then
begin
poziom:=findinhatcat(wea,web);
wya:=ilekotow(poziom,vn);
wyb:=wys(poziom,vn);
end
else
if wea=1 then begin wya:=0; wyb:=1 end;
writeln(wya,' ',wyb);
readln(wea,web);
end;
end.[/pascal]

Posted: Tue Jun 22, 2004 12:28 pm
by Rajib
Very less number of people use pascal :wink: . So better to post your algorithm or discuss where you face some problem.

Discussion is better than debuging. People have no much time to find the bug in your code... :lol:

Posted: Tue Jun 22, 2004 4:09 pm
by shamim
There are several threads regarding this problem, with many critical input. You should look into one of them.

at last i got ac!

Posted: Sat Jul 03, 2004 6:22 pm
by Stas
sory for my english :)

my program had a problem with comparing 2 real type variables.
the solution is
abs(a-b)<0.00000001 or something like that.
I hope this will help.

Posted: Sun Sep 26, 2004 3:10 pm
by hiloshi
hi yiuyuho.

I have got WA, so I checked output for your input.

Follow case:
390625 65535

I couldn't get any answer.
It's more than probable that program run for endless loop becase it can't find the value of N.
But I got Accept now.

I think your input is invalid.
This problem is undifficult, but everyone think any input is valid, and get WA.
My program is very simple.
I deleted some process for invalid input in my WA program, then I got Accept.

Posted: Sun Sep 26, 2004 5:39 pm
by yiuyuho
It was my mistake.

Posted: Tue Sep 28, 2004 9:45 am
by raghav
81 64 is correct input and it's a beautiful one too! Kudos to the creator!!!
9^2 8^2 is what it should be interpreted as. It could also be 3^4 2^6, which is why the test case is subtly different :)

Posted: Thu Nov 11, 2004 8:07 am
by Heartattack!
Have you tried the input format 64 1. The output should be 6 127. I'll try your code on my pc. Good luck. :o

Re: WA! 107 Please .. Help me

Posted: Thu Nov 11, 2004 5:18 pm
by Heartattack!
einstain000 wrote:

Code: Select all

#include<stdio.h>


      /* special condition ( 1,x)*/
		if( height == 1 ) {
			printf("0 %d\n",works);
			continue;
		}

[/quote]
Deary me, the special condition has the initial cat at height=1. So, no workers, good. Height of total cats=works....BAD 8) If there's only one cat of height 1 then the total height is of course 1. Everything else is ok. Hope you get AC.....Silly einstain :P  :P  :P  :P

about 107,thanks.

Posted: Mon Feb 07, 2005 4:41 am
by ioriyagami
I can't understand this problem. :(
what does this mean?

"The number of cats inside each (non-smallest) cat's hat is a constant, N. The height of these cats-in-a-hat is times the height of the cat whose hat they are in.

The smallest cats are of height one;
these are the cats that get the work done.
All heights are positive integers."

who can help me ?thanks.

Posted: Mon Feb 07, 2005 12:32 pm
by Eduard
Hello ioriyagami.
Lets initial cat hight be P.There is some number N(wich is not given) that each cat have N small cats in his hat.And each cat in hat of biggest cat has hight p/(N+1).It means that cat in hat of cat wich is in hat of biggest cat will have hight p/(n+1)^2.And so one until hight=1.
Eduard

thank you very much.

Posted: Fri Feb 11, 2005 7:46 pm
by ioriyagami
:D thanks.

107 wa

Posted: Tue Mar 29, 2005 3:53 am
by sunnycare
what's the limit of the input number?
shall i use BigInteger??