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>
const int SIZE = (1e6 + 10);
typedef long double ld;
int main()
{
//read
int N, Q; scanf("%d%d", &N, &Q);
int x[SIZE] = {0}, y[SIZE] = {0};
ld ax[SIZE] = {0}, ay[SIZE] = {0}, b[SIZE] = {0};
for (int i = 1; i <= N; i++)
scanf("%d%d", &x[i], &y[i]);
x[N + 1] = x[1]; y[N + 1] = y[1];
for (int i = 1; i <= N; i++)
{
ax[i] = ax[i - 1] + ((ld)x[i] + (ld)x[i + 1]) * ((ld)x[i] * (ld)y[i + 1] - (ld)x[i + 1] * (ld)y[i]);
ay[i] = ay[i - 1] + ((ld)y[i] + (ld)y[i + 1]) * ((ld)x[i] * (ld)y[i + 1] - (ld)x[i + 1] * (ld)y[i]);
b[i] = b[i - 1] + (ld)x[i] * (ld)y[i + 1] - (ld)x[i + 1] * (ld)y[i];
}
//output
for (int i = 0; i < Q; i++)
{
int u, v; scanf("%d%d", &u, &v);
ld ans_x, ans_y, sb, sax, say;
if (u < v)
{
sb = b[v - 1] - b[u - 1];
sax = ax[v - 1] - ax[u - 1];
say = ay[v - 1] - ay[u - 1];
}
else
{
sb = b[N] - b[u - 1] + b[v - 1];
sax = ax[N] - ax[u - 1] + ax[v - 1];
say = ay[N] - ay[u - 1] + ay[v - 1];
}
//close
ld c = (ld)x[v] * (ld)y[u] - (ld)x[u] * (ld)y[v];
sb += c;
sax += ((ld)x[v] + (ld)x[u]) * c;
say += ((ld)y[v] + (ld)y[u]) * c;
ans_x = sax / sb / 3.0L;
ans_y = say / sb / 3.0L;
printf("%.12Lf %.12Lf\n", ans_x, ans_y);
}
return 0;
}
|