36分求调
查看原帖
36分求调
1285722
zwz2010楼主2024/9/3 21:15
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct circle{
	double r,x,y;
	bool color=1;
}c[102];

double area(double r){
	return 3.14159265358979323846264338*r*r;
}
bool cmp(circle a,circle b){
	return a.r>b.r;
}

bool ifinclude(int i,int j){
	double d = pow(pow(c[i].y - c[j].y,2)+pow(c[i].x-c[j].y,2),0.5);
	return d<=fabs(c[i].r-c[j].r)?1:0;
}
int main(){
	int n;
	double needplus=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
	}
	sort(c+1,c+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(i==1) needplus+=area(c[i].r);
		else{
			for(int j=i-1;j>=1;j--){
				if(ifinclude(j,i)){
					c[i].color = !c[j].color;
					break;
				}
			}
			if(c[i].color) needplus+=area(c[i].r);
			else needplus-=area(c[i].r);
		}
	}
	printf("%.2f",needplus);
	return 0;
}

π的精度应该是够的

2024/9/3 21:15
加载中...