http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=199

 

#include<iostream>
#include
<cmath>
using namespace std;
int main()
{
    
int t;
    cin
>>t;
    
while(t--)
    
{
        
double x1,y1,r1,x2,y2,r2,temp,drr,x0,y0;
        cin
>>x1>>y1>>r1;
        cin
>>x2>>y2>>r2;        
        
if(r1>r2)//r1始终是小圆
        {
            temp
=r1; r1=r2; r2=temp;
            temp
=x1; x1=x2; x2=temp;
            temp
=y1; y1=y2; y2=temp;
        }

        drr
=sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
        
if(r2==r1)
        
{
            cout
<<"Impossible."<<endl;
            
continue;
        }

        
if(r1+drr<=r2)//内含或者内切
        {
            cout
<<"Impossible."<<endl;
            
continue;
        }

        
if(x1==0 && x2==0)//两圆心在y轴上
        {
            temp
=r1*drr/(r2-r1);
            
if(y1>y2)        
                printf(
"0.00 %.2lf\n",y1+temp);
            
else
                printf(
"0.00 %.2lf\n",y1-temp);
            
continue;
        }

        
if(y1==0 && y2==0)//两圆心在x轴上
        {
            temp
=r1*drr/(r2-r1);
            
if(x1>x2)
                printf(
"%.2lf 0.00\n",x1+temp);
            
else
                printf(
"%.2lf 0.00\n",x1-temp);
            
continue;
        }

        
        x0
=(r2*x1-r1*x2)/(r2-r1);
        y0
=(y1-y2)*r1/(r2-r1)+y1;

        printf(
"%.2lf %.2lf\n",x0,y0);
    }

    
return 0;
}