HDU 4617 weapon [cross-plane linear distance-Basic 3D ry]

Source: Internet
Author: User
Link: http://acm.hdu.edu.cn/showproblem.php? PID = 4617 weapon

Time Limit: 3000/1000 MS (Java/others) memory limit: 65535/32768 K (Java/Others)
Total submission (s): 224 accepted submission (s): 178


Problem description doctor D. are researching for a horrific weapon. the muzzle of the weapon is a circle. when it fires, rays form a cylinder that runs through the circle verticality in both side. if one cylinder of rays touch another, there will be an horrifle IC explosion. originally,
All circles can rotate easily. but for some unknown reasons they can not rotate any more. if these weapon can also make an explosion, then doctor D. is lucky that he can also test the power of the weapon. if not, he wocould try to make an explosion by other
Means. one way is to find a medium to connect two cylinder. but he need to know the minimum length of medium he will prepare. when the medium connect the surface of the two cylinder, it may make an explosion.


Input the first line contains an integer T, indicating the number of testcases. for each testcase, the first line contains one integer N (1 <n <30), the number of weapons. each of the next 3N Lines & #160; contains three float numbers. every 3 lines represent one
Weapon. the first line represents the coordinates of center of the circle, and the second line and the third line represent two points in the circle which surrounds the center. it is supposed that these three points are not in one straight line. all float
Numbers are between-1000000 to 1000000.


Output for each testcase, if there are two cylinder can touch each other, then output 'lucky', otherwise output then minimum distance of any two cylinders, rounded to two decimals, where distance of two cylinders is the minimum distance of any two point in the Surface
Of two cylinders.


Sample Input

330 0 01 0 00 0 15 2 25 3 25 2 310 22 -211 22 -111 22 -330 0 01 0 1.51 0 -1.5112 115 109114 112 110109 114 111-110 -121 -130-115 -129 -140-104 -114 -119.80196130 0 01 0 1.51 0 -1.5112 115 109114 112 110109 114 111-110 -121 -130-120 -137 -150-98 -107 -109.603922
 


Sample output

Lucky2.32Lucky
 


Source2013 multi-university training Contest 2


Recommendzhuyuanchen520


In fact, it is the best of pirated kb... Although he has already told me that it is the distance from orz kuangbin

Q: The doctor invented a weapon. the muzzle of the weapon is round. Once ignited, the energy rays will come out from both ends of the circle. [in this way, the bottom circle is determined, an unlimited-length cylinder: Once two of these energy cylinders meet each other [I think it includes tangent or a cylinder contains a cylinder, but the data does not exist. Then, an explosion occurs, so that the doctor can detect the power of the weapon.

In my opinion, as long as it is not the first case, we should be able to output lucky.

The test data of group T is given below. Each group of test data contains N cylinder. For each cylinder, the center coordinate of the bottom circle and the two points on the bottom circle are given.
If the given circle has at least two met cylinders, it is obvious that the doctor can directly detect their power and output lucky
If no cylinder encounters each other, find the nearest adjacent distance in all the cylinders, that is, find the smallest distance.

Algorithm: horizontal line distance: [Baidu encyclopedia]
Vector Method: first obtain the public method vector of two cross-plane straight lines, and then obtain the projection length of the link line segments of two points on the two cross-plane straight lines on the public method vector.
Idea: Compare each circular Surface with all other circular surfaces to see if the cylinder they form has an intersection
How to Implement: Find the distance between the axes of the cylinder and their radius.
I personally think that we don't need to consider whether the axes are parallel or even co-linear. It should be because the data is relatively watery. How can this problem be solved through orz?

Code:

Accepted 4617 15 ms 244 K 3486 B C ++ Freeze
# Include <stdio. h> # include <math. h> # include <algorithm> using namespace STD; const int maxn = 30 + 10; const double EPS = 1e-10; int DCMP (Double X) // precision {If (FABS (x) <EPS) return 0; else return x <0? -1: 1;} struct point3d {Double X; Double Y; Double Z; point3d () {} point3d (double _ x, double _ y, double _ z) {x = _ x; y = _ y; Z = _ z;} point3d operator-(const point3d & B) const {return point3d (x-b.x, y-b.y, z-b.z );} double operator * (const point3d & B) const // Point product {return x * B. X + Y * B. Y + z * B. z;} point3d operator ^ (const point3d & B) const // Cross Product {return point3d (y * B. z-z * B. y, z * B. x-x * B. z, x * B. y-y * B. X );} Void input () {scanf ("% lf", & X, & Y, & Z) ;}; typedef point3d vector3d; struct circle {point3d O, p1, P2; void input () {o. input (); p1.input (); p2.input () ;}} circle [maxn]; double length3d (point3d p) // vector length {return SQRT (p * P );} // two cross-plane linear distance [projection of the line of points on two straight lines on its normal vector] Double CAL (point3d P1, vector3d K1, point3d P2, vector3d K2) {point3d NV = k1 ^ K2; // normalvector return FABS (NV * (p1-p2)/length3d (NV);} int Ma In () {int t; int N; scanf ("% d", & T); While (t --) {scanf ("% d", & N ); for (INT I = 0; I <n; I ++) circle [I]. input (); bool flag = false; double min = 3000000; For (INT I = 0; I <n &&! Flag; I ++) {for (Int J = I + 1; j <n &&! Flag; j ++) {circle C1 = circle [I]; Circle C2 = circle [J]; double R1 = length3d (c1.p1-c1.o ); // circle radius double r2 = length3d (c2.p1-c2.o); vector3d k1 = (c1.p1-c1.o) ^ (c1.p2-c1.o ); // direction of the Axis vector3d k2 = (c2.p1-c2.o) ^ (c2.p2-c2.o); double D = CAL (c1.o, K1, c2.o, K2 ); // If (d <= R1 + R2) // The intersection, tangent, and even content of the two circles can be [the question is not rigorous, no tangent and contains data] {flag = true; break;} min = min (Min, d-r1-r2) ;}}if (FLAG) printf ("Lucky \ n"); else if (DCMP (min) <= 0) printf ("Lucky \ n "); else printf ("%. 2lf \ n ", min);} return 0 ;}

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.