We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Geometry
  4. Spheres

Spheres

Problem
Submissions
Leaderboard
Discussions
Editorial

Initially, two non-touching spheres of radii R1 and R2 are lying in space at rest. Both of them are then given accelerations a1 and a2 respectively at time=0. Find whether they will ever come in contact. Their initial positions are represented as (x1,y1,z1) and (x2,y2,z2) respectively. Accelerations have respective components in 3D. They are represented as (a1i,a1j,a1k) and (a2i,a2j,a2k) respectively.

Input Format
The first line contains T, the number of test cases.
Each test case consists of five lines, where the first line contains R1 and R2. The next two lines contain position and acceleration of the first sphere. The next two lines after this contain position and acceleration of the second sphere. All numbers in input are integers.

Output Format
For each test case, print YES, if the spheres come in contact. Otherwise, print NO (quotes for clarity).

Constraints
1 ≤ T ≤ 104
1 ≤ R1, R2 ≤ 102
-102 ≤ x1, y1, z1 , x2 , y2 , z2 ≤ 102
-102 ≤ a1i , a1j , a1k , a2i , a2j , a2k ≤ 102

Sample input

2
1 2
0 0 0
-1 0 0
4 0 0
1 0 0
1 2
0 0 0
100 0 0
4 0 0
0 0 0

Sample output

NO
YES

Explanation
For first testcase, both spheres go in opposite directions, so they'll never come in contact.
For second testcase, second sphere is not moving while first sphere is accelerating towards the second sphere. So they come in contact.

Author

darkshadows

Difficulty

Medium

Max Score

30

Submitted By

1174

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website