FZU - 2213 Common Tangents (数学)


 Problem 2213 Common Tangents

Accept: 763    Submit: 2233
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Two different circles can have at most four common tangents.

The picture below is an illustration of two circles with four common tangents.

Now given the center and radius of two circles, your job is to find how many common tangents between them.

 Input

The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).

For each test case, there is one line contains six integers x1 (−100 ≤ x1 ≤ 100), y1 (−100 ≤ y1 ≤ 100), r1 (0 < r1 ≤ 200), x2 (−100 ≤ x2 ≤ 100), y2 (−100 ≤ y2 ≤ 100), r2 (0 < r2 ≤ 200). Here (x1, y1) and (x2, y2) are the coordinates of the center of the first circle and second circle respectively, r1 is the radius of the first circle and r2 is the radius of the second circle.

 Output

For each test case, output the corresponding answer in one line.

If there is infinite number of tangents between the two circles then output -1.

 Sample Input

3
10 10 5 20 20 5
10 10 10 20 20 10
10 10 5 20 10 5

 Sample Output

4
2
3

 Source

第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)


【题意】

tangents 是切线的意思,  问相同切线 化几条,

肯定是圆心距跟半径的 问题

【思路】

相离  4 条

外切  3 条

相交 2 条

内切 1 条

内含 0 条

注意: 当两个圆等大位置一样是 -1


一直把内含 写成  -1  WA了好几发


【代码实现】


//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define S1(n)    scanf("%d",&n)
#define SL1(n)   scanf("%I64d",&n)
#define S2(n,m)  scanf("%d%d",&n,&m)
#define SL2(n,m)  scanf("%I64d%I64d",&n,&m)
#define Pr(n)     printf("%d\n",n)
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=505;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        double d;
        double x1,y1,x2,y2,r1,r2;
        cin>>x1>>y1>>r1>>x2>>y2>>r2;
        d= sqrt( fabs(y2-y1)*fabs(y2-y1) +fabs(x2-x1)*fabs(x2-x1));
        double r= r1+r2;
        //cout <<d<<" "<<r<<endl;

        if(d==0&&r1==r2)// bao han
            printf("-1\n");
        else if(d>r)// li
            printf("4\n");
        else if(d==r)// qie
            printf("3\n");
        else if(d<r&&d>=max(r1,r2))// jiao
            printf("2\n");
        else if(d<r&&(d+min(r1,r2)==max(r1,r2)))// nei qie
            printf("1\n");
        else
            printf("0\n");
    }
    return 0;
}



131

posted @ 2017-11-20 19:28  Sizaif  阅读(171)  评论(0编辑  收藏  举报