- 关键是要考虑到两个两个圆的直径r1==r2的情况和一个圆在另外一个圆内的情况。
- 顺便,c++输出格式的控制,cout << fixed表示固定小数点,cout << showpoint表示强制显示小数点,cout << setprecision(x)表示输出精度。如果没有cout << fixed作为前缀条件,那么setprecision(x)表示整个输出为数为x位。加上cout << fixed作为条件,那么setprecision(x)表示小数点的为数为x位。
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()

{
int numberOfCase;
cin >> numberOfCase;
for(int i = 0; i < numberOfCase; i ++)
{
int x1, y1, r1, x2, y2, r2;
cin >> x1 >> y1 >> r1
>> x2 >> y2 >> r2;
double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
if((d <= fabs(r1 - r2)) || (x1 == x2 && y1 == y2) || (r1 == r2))
cout << "Impossible." << endl;
else
{
double x = double(r1 * x2 - r2 * x1)/(r1 - r2);
double y = double(r1 * y2 - r2 * y1)/(r1 - r2);
cout << fixed << showpoint;
cout << setprecision(2) << x << ' ' << y << endl;
}
}
return 0;
}
本文探讨了两个圆相交的数学问题,包括处理圆在特定位置关系下的特殊情况,并介绍了C++中使用cout进行精确输出格式控制的方法。
419

被折叠的 条评论
为什么被折叠?



