This page is still under construction.

Parts of this page are still being built. What you see may change.

The Amazing Human Cannonball

Time limit1sMemory limit1024 MB

Summary
For each test case, the task checks whether the cannonball's height where it crosses the wall is at least 1 m above the lower edge and at least 1 m below the upper edge.
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

The amazing human cannonball show is coming to town, and you are asked to double-check their calculations to make sure no one gets injured! The human cannonball is fired from a cannon placed x1x_1 away from a vertical wall. The wall has a hole that the cannonball must fly through. The lower edge of the hole is at height h1h_1, and the upper edge is at height h2h_2. The initial velocity is v0v_0, and the angle of the cannon relative to the ground is θ\theta.

Thanks to their innovative suits, human cannonballs can fly without air resistance, so their trajectory can be modeled with the following formulas: x(t)=v0tcos⁡θ,y(t)=v0tsin⁡θ−12gt2x(t) = v_0 t \cos\theta, \quad y(t) = v_0 t \sin\theta - \frac{1}{2} g t^2 where x(t),y(t)x(t), y(t) give the position of the cannonball at time tt when it is fired from point (0,0)(0, 0). gg is the acceleration due to gravity (g=9.81 m/s2g = 9.81\ m/s^2).

Write a program to determine whether the human cannonball can pass safely through the hole in the wall. To pass safely, the point where the trajectory crosses the centerline of the wall must have a vertical safety margin of 1 m above the lower edge and 1 m below the upper edge.

Input

The input has at most 100 test cases. The first line contains an integer NN, the number of test cases. Each test case has five parameters, v0v_0 θ\theta x1x_1 h1h_1 h2h_2, separated by spaces. v0v_0 (0<v0≤2000 < v_0 \le 200) is the initial velocity of the ball in m/s. θ\theta is the angle in degrees (0<θ<900 < \theta < 90). x1x_1 (0<x1<10000 < x_1 < 1000) is the distance from the cannon to the wall. h1h_1 and h2h_2 (0<h1<h2<10000 < h_1 < h_2 < 1000) are the heights of the lower and upper edges of the wall. All numbers are floating point numbers.

Output

If the cannonball can pass safely through the wall, print Safe. Otherwise, print "Not Safe"!

Examples1

  1. Example 1

    Input
    11
    19 45 20 9 12
    20 45 20 9 12
    25 45 20 9 12
    20 43 20 9 12
    20 47.5 20 9 12
    20 45 17 9 12
    20 45 24 9 12
    20 45 20 10 12
    20 45 20 9 11
    20 45 20 9.0 11.5
    20 45 18.1 9 12
    
    Expected output
    Not Safe
    Safe
    Not Safe
    Not Safe
    Not Safe
    Not Safe
    Not Safe
    Not Safe
    Not Safe
    Safe
    Safe