# [HDU](6354)Everything Has Changed ---- 余弦定理+计算几何

AC代码：

#include<bits/stdc++.h>
using namespace std;
const double PI = 4*atan2(1.0,1.0);
struct PPoint
{
double x,y;
};
double len(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
struct Circle
{
double x,y,r;
};
int main()
{
#ifdef LOCAL_FILE
freopen("in.txt","r",stdin);
#endif // LOCAL_FILE
int t;
scanf("%d",&t);
while(t--)
{
Circle cc[105];
double R;
int m;
scanf("%d %lf",&m,&R);
for(int i=0;i<m;i++)
scanf("%lf %lf %lf",&cc[i].x,&cc[i].y,&cc[i].r);
double cir1 = 2*PI*R;
double ans = cir1;
for(int i=0;i<m;i++)
{
double d1 = len(cc[i].x,cc[i].y,0,0);
double cir2 = 2*PI*cc[i].r;
if(d1+cc[i].r == R)
{
ans+=cir2;
}
else if(d1 == cc[i].r+R)
continue;
else if(d1+cc[i].r<R)
continue;
else
{
double a1 = acos((R*R+d1*d1-cc[i].r*cc[i].r)/(2*d1*R));
double a2 = acos((cc[i].r*cc[i].r+d1*d1-R*R)/(2*d1*cc[i].r));
double c1 = 2*a1*R;
double c2;
if(a2<=PI/2)
{
c2 = 2*a2*cc[i].r;
ans+=c2;
ans-=c1;
}
else if(a2>PI/2)
{
a2 = PI-a2;
c2 = 2*a2*cc[i].r;
ans = ans+(cir2-c2);
ans-=c1;
}
}
}
printf("%.20f\n",ans);
}
return 0;
}