1075. Thread in a spacetime limit:1.0 second
Memory limit:64 Mbthere is three points in a 3-dimensional space:
A,
Band
C. All the coordinates of the points is integer numbers with absolute values not greater than 1000. A solid ball with a center at the point
Cis firmly fixed. A radius of the ball is
RA positive integer number. Distances from the point
Cto the points
Aand
Bis strictly greater than
R. It is necessary to stretch a thread of minimal length between points
Aand
B. Surely, the thread should is outside of the ball. You is to find out a length of the thread. Inputthe first three lines contain coordinates of the points
A,
Band
Crespectively. The fourth one contains a radius
Rof the ball. Outputshould contain a minimal length of the thread to within 2 symbols after a decimal point. You should the output answer with the or more digits. Sample
input |
Output |
0 0 1212 0 010 0 1010 |
19.71 |
problem Author:Alexander Mironenko
problem Source:Ural State univerisity Personal Contest Online February ' 2001 Students Session
Tags:Geometry()difficulty:1029 Test instructions: Give three of the hour in space. In the middle of a point, a small ball is fixed. The radius of the ball is R. The remaining two points are outside the ball. Use the minimum length of the rope to connect the remaining two points. Find the length of the rope. Analysis: Because there are only three points, so can be placed on the plane to consider. If the line does not go through the circle, it is obvious that distance can be obtained directly. If passing, then there is a simple knowledge of plane geometry. And do not need to pay attention to the space, directly with the angle of the calculation.
1 /**2 Create by Yzx-stupidboy3 */4#include <cstdio>5#include <cstring>6#include <cstdlib>7#include <cmath>8#include <deque>9#include <vector>Ten#include <queue> One#include <iostream> A#include <algorithm> -#include <map> -#include <Set> the#include <ctime> -#include <iomanip> - using namespacestd; -typedefLong LongLL; +typedefDoubleDB; - #defineMIT (2147483647) + #defineINF (1000000001) A #defineMLL (1000000000000000001LL) at #defineSZ (x) ((int) (x). Size ()) - #defineCLR (x, y) memset (x, y, sizeof (x)) - #definePUF Push_front - #definePub push_back - #definePOF Pop_front - #definePOB pop_back in #defineFT first - #defineSD Second to #defineMk Make_pair + -InlineintGetint () the { * intRet =0; $ CharCh =' ';Panax Notoginseng BOOLFlag =0; - while(! (Ch >='0'&& Ch <='9')) the { + if(Ch = ='-') Flag ^=1; ACh =GetChar (); the } + while(Ch >='0'&& Ch <='9') - { $RET = RET *Ten+ Ch-'0'; $Ch =GetChar (); - } - returnFlag? -Ret:ret; the } - Wuyi ConstDB EPS = 1e-7; the struct Point - { Wu DB x, y, Z; -InlinevoidRead () About { $Cin >> x >> y >>Z; - } - } A, B, C; - DB R; A +InlinevoidInput () the { - A.read (); $ B.read (); the C.read (); theCIN >>R; the } the - Inline DB SQR (db x) in { the returnX *x; the } About the inline DB Dist (point A, point B) the { the returnsqrt (SQR (a.x-b.x) + SQR (A.Y-B.Y) + SQR (A.Z-b.z)); + } - theInlinevoidSolve ()Bayi { theDB ans =0.0; the -DB AB =Dist (A, b), -AC =Dist (A, c), theBC =Dist (b, c); the theDB angle = theACOs ((SQR (AC) + SQR (BC)-SQR (AB))/(2.0* AC * BC)- -ACOs (R/AC)-ACOs (r/BC); the if(Angle <=EPS) the { theprintf"%.2lf\n", AB);94 return; the } the theAns + = sqrt (SQR (AC)-SQR (R));98Ans + = sqrt (SQR (BC)-SQR (R)); AboutAns + = angle *R; - 101printf"%.2lf\n", ans);102 }103 104 intMain () the {106Freopen ("g.in","R", stdin);107 Input ();108 Solve ();109 return 0; the}
View Code
Ural 1075. Thread in a Space