原题:1333
题意:对于一个1*1的方格,其中包含n个给出圆心和半径的圆,问这些圆的覆盖面积所占比例
解:因为题目允许的误差较大,将1*1的方格离散化,再对每一个点进行扫描。
#include <iostream>
using namespace std;
#include <math.h>
double a[20][5], ans = 0;
int n;
double sqr(double x) {
return x*x;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i][1] >> a[i][2] >> a[i][3];
for (double i = 0; i <= 1; i += 0.001)
for (double j = 0; j <= 1; j += 0.001) {
for (int k = 1; k <= 10; k++)
if (sqrt(sqr(i-a[k][1])+sqr(j-a[k][2])) <= a[k][3]) {
ans++;
break;
}
}
printf("%lf", ans*100/1000.0/1000.0);
}