Source of C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<cstdio>
#include<cmath>
#include<cstring>
#define pi 3.14159265
using namespace std;
int main() {
double ans;
int T, n, b[128][128], x, y, minx, miny, maxx, maxy;
scanf("%d", &T);
while (T--) {
ans = 0;
memset(b, 0, sizeof(b));
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &x, &y);
if (i == 0) {
minx = maxx = x;
miny = maxy = y;
}
else {
if (x < minx)
minx = x;
if (x > maxx)
maxx = x;
if (y < miny)
miny = y;
if (y > maxy)
maxy = y;
}
b[x][y] = 1;
}
for (int i = minx; i <= maxx + 1; ++i)
for (int j = miny; j <= maxy + 1; ++j) {
if (b[i-1][j-1] + b[i-1][j] + b[i][j-1] + b[i][j] > 2)
ans += 1.0;
else if (b[i-1][j-1] + b[i-1][j] + b[i][j-1] + b[i][j] == 1)
ans += pi/4;
else if (b[i-1][j-1] + b[i-1][j] + b[i][j-1] + b[i][j] == 2) {
if ((b[i-1][j-1] == 1 && b[i][j] == 1) || (b[i][j-1] == 1 && b[i-1][j] == 1))
ans += 1.0;
else
ans += sqrt(3)/4 + pi/6;
}
}
printf("%.5f\n", ans);
}
return 0;
}

返回