On Friday, April 13, 2018 at 2:36:19 AM UTC+1, Yupeng Gu wrote:
> from math import sqrt,pi,sin,cos
> tt = int(raw_input())
>
> _mid = sqrt(2.0)
>
> def findRad(lower,upper,target,func):
> if upper-lower<0.00000001:
> return upper
> mid = (upper+lower)/2.0
> if func(mid-0.000001)>func(mid) or target<=func(mid):
> return findRad(lower,mid,target,func)
> else:
> return findRad(mid,upper,target,func)
>
> for t in xrange(1,tt+1):
> area = float(raw_input())
> print "Case #{0}:".format(t)
> if area<_mid-0.000001:
> rad = findRad(0.0,pi/4.0,area,lambda r:cos(r)+sin(r))
> print "{0} {1} {2}".format(cos(rad)/2.0,sin(rad)/2.0,0)
> print "{0} {1} {2}".format(-sin(rad)/2.0,cos(rad)/2.0,0)
> print "0 0 0.5"
> elif abs(area-_mid)<0.000001:
> print "0.3535533905932738 0.3535533905932738 0"
> print "-0.3535533905932738 0.3535533905932738 0"
> print "0 0 0.5"
> else:
> x = sqrt(2.0)/4.0
> rad = findRad(0.0,pi/4.0,area,lambda r:sqrt(2)*cos(r)+sin(r))
> print "{0} {1} {2}".format(x,x*cos(rad),-x*sin(rad))
> print "{0} {1} {2}".format(-x,x*cos(rad),-x*sin(rad))
> print "{0} {1} {2}".format(0,cos(rad)/2.0,sin(rad)/2.0)
Because the the directions to the face centers must be orthogonal.
The answer your code gives for area 1.5 is
0.353553390593 0.352062072584 -0.0324391283414
-0.353553390593 0.352062072584 -0.0324391283414
0 0.497890957846 0.045875855252
but the dot product between the centers of the last two is
(0.352 * 0.497 - 0.032 * 0.045)
which is not zero.
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/e9598515-952e-450c-b0a4-df2148e828fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.