Experiment 12:problem D: Judging the relationship between two circles

Source: Internet
Author: User

Home Web Board Problemset Standing Status Statistics
Problem D: Judging the relationship between two circles Problem D: Determine the relationship between two circles time limit: 1 Sec Memory Limit: MB
Submit: 381 Solved: 325
[Submit] [Status] [Web Board] Description

Defines the point class, which includes two properties of the double type, representing the horizontal ordinate of one of the two-dimensional spaces, defining its necessary constructors and copy constructors.

Defines the Circle class, which includes the object of the point class and a double type of data as its properties, representing the center coordinate and radius, and defining its necessary constructors, copy constructors. Define member functions for the Circle class:

int judgerelation (const circle& another)

Used to determine the position relationship between the current circle and the another. The return value of the function is determined according to the following rules: When two circles are out of time, 1 is returned, 2 is returned when two circles are included, two is returned when the 3 circles are in the same line, two is returned in 4 circles, and two is returned when 5 circles intersect.

Input

Line 1th n>0 indicates the number of test cases.

Each test case consists of 2 rows, the 1th row is the position and radius of the 1th circle, and the 2nd line is the position and radius of the 2nd circle.

Output

Each test case corresponds to a row of output, outputting a position relationship between two circles. See examples.

Sample Input0 1020 0 101 1 0 0 5 1015 0 Ten .Sample Outputoutsideinsideexternally tangentinternally tangentintersectionHINT

Outer and inner are two circles without any intersection, but inclusion means that a circle is completely contained within another, otherwise it is outside.

Append codeappend.cc, [Submit] [Status] [Web Board]

??? < Chinese????? 中文版???
All Copyright Reserved 2010-2011 sdustoj TEAM
GPL2.0 2003-2011 hustoj Project TEAM
Anything about the problems admin:admin

#include <iostream>#include<cmath>using namespacestd;classpoint{ Public:    Doublex, y; Point (DoubleA=0,Doubleb=0): X (a), Y (b) {}~Point () {}};classcircle{friendclassPoint ; Public: Point P; DoubleR; Circle (Point A,DoubleR):p (a), R (r) {}~Circle () {}intJudgerelation (Constcircle&cc) {DoubleDc=sqrtl ((cc.p.x-p.x) * (cc.p.x-p.x) + (CC.P.Y-P.Y) * (CC.P.Y-p.y)); if(Fabs (DC-(R + CC.R)) < 1e-6) {            return 3; }        if(Fabs (Dc-fabs (R-CC.R)) < 1e-6)        {            return 4; }        if(DC < Fabs (R-CC.R))return 2; if(DC > R +CC.R)return 1; return 5; }};intMain () {intcases; Doublex, Y, R; CIN>>cases;  for(inti =0; i < cases; i++) {cin>>x>>y>>R;        Point P1 (x, y);        Circle C1 (P1, R); CIN>>x>>y>>R;        Point P2 (x, y);        Circle C2 (P2, R); Switch(C1. Judgerelation (C2)) { Case 1: cout<<"Outside"<<Endl;  Break;  Case 2: cout<<"Inside"<<Endl;  Break;  Case 3: cout<<"Externally tangent"<<Endl;  Break;  Case 4: cout<<"internally Tangent"<<Endl;  Break;  Case 5: cout<<"intersection"<<Endl; }    }}

Experiment 12:problem D: Judging the relationship between two circles

Related Article

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.