题目链接:http://acm.fzu.edu.cn/problem.php?pid=2213
题 意:告诉你两个圆的圆心与半径,要你找出他们的公共切线的个数。
思 路:直接计算所有的情况。
代码如下:
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
typedef __int64 LL;
int main()
{
int T;
scanf ( "%d", &T );
while( T-- )
{
double x1,y1,r1,x2,y2,r2;
scanf ( "%lf %lf %lf %lf %lf %lf", &x1, &y1, &r1, &x2, &y2, &r2 );
if( x1 == x2 && y1 == y2 )//圆心相同时
{
if( r1 == r2 ) printf("-1\n");
else printf("0\n");
continue;
}
double d = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
double k = r1+r2;
if( r1 < r2 && r1+d < r2){//一个圆被另一个圆包围
printf("0\n");
continue;
}
if( r1 > r2 && r2+d < r1 )
{
printf("0\n");
continue;
}
if( r1 + d == r2 || r2+d == r1 )
{
printf("1\n");
continue;
}
if( k < d )//两圆相交、相离、相切
printf("4\n");
else if( k == d )
printf("3\n");
else printf("2\n");
}
return 0;
}