版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jiayizhenzhenyijia/article/details/81558510
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6354
题意:用一堆圆来切割一个圆心为原点,半径为R的圆A,问切割完毕后圆A外围剩余部分的周长(图中的红线部分)。
#include<iostream>
#include<cstdio>
#include<cmath>
#define PI acos(-1.0)
using namespace std;
struct node
{
int x,y,r;
}a[105];
double R,m;
double x,y,r;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&m,&R);
double s;
s=2*R*PI;
for(int i=0;i<m;i++)
{
scanf("%lf%lf%lf",&x,&y,&r);
double d,c1,c2,s2;
d=sqrt(x*x+y*y);
if((d<R+r)&&(d>fabs(R-r)))
{
c1=2*acos((R*R+d*d-r*r)/(2*R*d));
c2=2*acos((r*r+d*d-R*R)/(2*r*d));
s-=c1*R;
s+=c2*r;
}
else if(d==fabs(R-r))
{
s+=2*PI*r;
}
}
printf("%lf\n",s);
}
}