Re: Problem with conditional statement
- From: "Stuart" <stuart@xxx>
- Date: Tue, 19 Jun 2007 18:28:07 +0100
"mukesh tiwari" <mukeshtiwari.iiitm@xxxxxxxxx> wrote in message
news:1182190699.734601.203130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi everybody i am trying to solve problemYou seem to have slipped up in your working! Check!
http://acm.uva.es/p/v105/10512.html.
my solution is
(x+y)y=P (1)
(x-y)x=Q (2)
(1+(y/x))xy=P (1)//taking x outside
(1-(y/x))x^2=Q (2)
dividing 1 and 2 and let (y/x)=k
(1+k)k/(1-k)=P/Q;
solving for k
k=-(P+Q) +-sqrt((P+Q)^2+4PQ)/2Q;
since x>=y so we can not take -ve sign as it will make |k|>1 which isI think your logic here is flawed! Check!
not possible so i take only +ve sign ;
solution is possible only when
(P+Q)^2+4PQ is perfect square .
after determining k we can find out x and y
so my values are
x=+-sqrt(Q/(1-k));
and y=+-sqrt(Pk/(1+k));
now my problem is based on for each value of x we have two values of
y so we have 4 pair of values .So which value to output .
It is not advisable to compute y this way as you introduce an unnecessary
ambiguity in the sign which would lead to an erroneous result. You would do
better using your relation: k = y/x => y = k*x
With corrections your approach is getting there - be careful though as one
solution to k leads to non-integer solutions while the other leads to
success. However, which one will depend on the values of P & Q. (On a
quick look transposing P & Q switches which root you need to take for k).
An interesting approach - but probably computationally inefficient because
of the SQRT. But it does seem to yield solutions in the negative integer
domain where appropriate.
--
Stuart
.
- References:
- Problem with conditional statement
- From: mukesh tiwari
- Problem with conditional statement
- Prev by Date: Re: Problem with conditional statement
- Next by Date: Re: Another question about big floating point
- Previous by thread: Re: Problem with conditional statement
- Next by thread: Open Source Java Library for Textile
- Index(es):
Relevant Pages
|