BNU 51638 Air Hockey Three-point two-point method

Source: Internet
Author: User

Air Hockey

Bored river boat classmates and bored fish swell students are very fond of playing table hockey (actually just like listening to the sound of the ball collision). In the boring day, the bored river boat students think of a boring play: two people at the same time two balls on the table, while hitting out, and then listen to the two balls hit together when the sound. However, they are not very good at the accuracy of the shot, so the two balls will not be able to collide.

Now assume that the desktop is infinitely large and absolutely smooth, giving the initial position, radius, and movement speed of the two balls, ensuring that the two balls are initially untouched. Bored river boat students want to know whether two goals can collide (contact is think of collision), if can, he wants to know two ball collision time (from two people to start timing), if not, he would like to know the whole process of the minimum distance between two balls, here the two ball distance is defined as two balls take two points distance of the minimum value, The data guarantees that in this case the answer is not less than. Note that the puck is a cylinder, which looks down from the air as a circle, and in this problem, the height of the puck is negligible.

Input

The first line is a positive integer that represents the number of groups of test data,

Each set of test data contains two rows,

The first line contains five integers that are not greater than the absolute value, representing the initial position, radius, and motion velocity of the first ball.

Output

For each set of test data, if two balls can collide, output two ball collision time, otherwise the output of the whole process of the two ball distance of the minimum, relative error can not exceed,

That is, the output is, the standard answer is, if satisfied, then the output will be considered the correct answer. Sample Input
20 0 2 1 011 0 1-1 00 0 2 1 011 5 1-1 0
Sample Output
4.00000000002.0000000000
Hint

For the first set of samples, the two balls collide 4 seconds after the hit,

For the second set of samples, the two balls do not collide and the two balls are closest to each other 5.5 seconds after hitting the ball, and the distance is 2.0.

SOURCE 14th session of Beijing Normal University program design competition final author

Exercises

  

Two different sizes of cylinders in different directions at different speeds at the same time, ask whether it can collide, can not give the minimum distance, can give a collision time.

Problem Solving Ideas:

Can prove that the two balls in the course of the movement must be close to the next or direct, so can be three minutes to find the distance between the two Circles Circle Center, if the two circle nearest distance (the nearest distance two circle radius) is less than 1e-6 (the condition of the dry said), then can collide, and then to 0~ The time to reach the nearest point is the interval two points to find the collision time, otherwise directly output two Circle center nearest distance minus the sum of two circle radius.

#include <bits/stdc++.h>using namespacestd;Const intN = 1e6+ -, M = 1e6+Ten, mod = 1e9+7, INF = 1e9+ +; typedefLong Longll;Doublex[2], y[2], r[2], vx[2], vy[2];inlineDoubleSDoublea) {    returnA *A;}DoubleDDoublet) {    Doublex0 = x[0] + vx[0] *T; DoubleX1 = x[1] + vx[1] *T; DoubleY0 = y[0] + vy[0] *T; DoubleY1 = y[1] + vy[1] *T; returnsqrt (S (x1-x0) + S (y1-y0))-r[0]-r[1];}intMain () {intT; scanf ("%d", &T);  while(t--) {scanf ("%LF%LF%LF%LF%LF", &x[0], &y[0], &r[0], &vx[0], &vy[0]); scanf ("%LF%LF%LF%LF%LF", &x[1], &y[1], &r[1], &vx[1], &vy[1]); DoubleL =0, r =1e10;  while(r-l>1e-7)//find the lowest point in three points first        {            DoubleMID1 = L + (r-l)/3, Mid2 = R-(r-l)/3; Doubleans1 = d (mid1), ans2 =d (MID2); if(ans1 <= ans2) R =Mid2; ElseL =Mid1; }        if(d (L) >=1e-6) printf ("%.10lf\n", D (l)); Else//0 points for two points{L=0;  while(R-l > 1e-7)            {                DoubleMid = (R + L)/2; if(d (Mid) >0) L =mid; ElseR =mid; } printf ("%.10f\n", L); }    }}

BNU 51638 Air Hockey Three-point two-point method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.