题意:给你两个圆的圆心坐标和半径,判断两个圆公切线数目。
思路:考虑两个圆间公切线的情况,两个圆的位置关系分为相离,相交,外切,内切,内含,重合,公切线数分别为4,2,3,1,0,-1。
#include<iostream>
using namespace std;
int main() {
int test;
cin>>test;
while(test--) {
int x1,y1,r1,x2,y2,r2;
cin>>x1>>y1>>r1>>x2>>y2>>r2;
int d=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if( d > (r1+r2)*(r1+r2) ) cout<<"4"<<endl;
else if( d==0 && r1==r2 ) cout<<"-1"<<endl;
else if( d==(r1-r2)*(r1-r2) ) cout<<"1"<<endl;
else if( d==(r1+r2)*(r1+r2) ) cout<<"3"<<endl;
else if( (r1-r2)*(r1-r2) < d && d < (r1+r2)*(r1+r2) ) cout<<"2"<<endl;
else cout<<"0"<<endl;
}
return 0;
}