#include #include #include using namespace std; // // Consider the field from an overhead view: // // x P (x,y) // _/|\_ // _/ | \_ // a _/ | \_ c // _/ b| \_ // _/ | \_ // / | \ // x-----------x-----------x // A (-D,0) B (0,0) C (+D,0) // // P is the point on the field directly under the cloud. // Assume that the plane drawn here is at the height H. // // b^2 = x^2 + y^2 by Pythagorean // // a^2 = (x - (-D))^2 + y^2 by Pythagorean // = x^2 + y^2 + 2Dx + D^2 // = b^2 + 2Dx + D^2 (1) // // c^2 = (x - (+D))^2 + y^2 by Pythagorean // = x^2 + y^2 - 2Dx + D^2 // = b^2 - 2Dx + D^2 (2) // // a^2 + c^2 = 2b^2 + 2D^2 by (1) and (2) // a^2 + c^2 - 2b^2 = 2D^2 (3) // // Let z be the distance between the plane and the cloud. // By trig, z = a tan(alpha) = b tan(beta) = c tan(gamma) // // Let p = 1 / tan(alpha). Therefore, a^2 = z^2 * p^2 // Let q = 1 / tan(beta). Therefore, b^2 = z^2 * q^2 // Let r = 1 / tan(gamma). Therefore, c^2 = z^2 * r^2 // // p^2*z^2 + r^2*z^2 - 2*q^2*z^2 = 2D^2 by (3) // z^2 ( p^2 + r^2 - 2q^2 ) = 2D^2 // z^2 = 2 * D^2 / ( p^2 + r^2 - 2q^2 ) // z = sqrt ( 2 * D^2 / ( p^2 + r^2 - 2q^2 ) ) // double sqr(double x) { return x * x; } int main(void) { double d, p; cin >> d >> p; while (1) { double al, be, ga; cin >> al >> be >> ga; if (al == 0 && be == 0 && ga == 0) break; al *= M_PI / 180.0; be *= M_PI / 180.0; ga *= M_PI / 180.0; double den = 1/sqr(tan(al)) + 1/sqr(tan(ga)) - 2/sqr(tan(be)); if (den < 1e-10) den = 1e-10; double h = sqrt(2.0 * d * d / den) + p; printf("%d\n", (int)(h+0.5)); } return 0; }