forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10456.cpp
106 lines (102 loc) · 1.93 KB
/
10456.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <bits/stdc++.h>
using namespace std;
int x[31], y[31], x1, y1_, n, tx[31], ty[31], len, totalarea;
int GCD(int a, int b)
{
return (b == 0) ? a : GCD(b, a % b);
}
int main()
{
while (scanf("%d", &n) == 1)
{
for (int i = 0; i < n; i++)
{
scanf("%d %d", x + i, y + i);
}
x[n] = x[0];
y[n] = y[0];
totalarea = 0;
for (int i = 0; i < n; i++)
{
totalarea += x[i] * y[i + 1] - x[i + 1] * y[i];
}
int k;
scanf("%d", &k);
while (k--)
{
scanf("%d %d", &x1, &y1_);
int p = 0;
len = 0;
for (int i = n - 1; i >= 0; i--)
if ((x[i + 1] - x[i]) * (y1_ - y[i]) == (x1 - x[i]) * (y[i + 1] - y[i]))
{
p = i;
}
tx[len] = x1;
ty[len++] = y1_;
tx[len] = x[p + 1];
ty[len++] = y[p + 1];
for (int i = (p + 2) % n; i != p; i = (i + 1) % n)
{
tx[len] = x[i];
ty[len++] = y[i];
tx[len] = x1;
ty[len] = y1_;
int temp = 0;
for (int j = 0; j < len; j++)
{
temp += tx[j] * ty[j + 1] - tx[j + 1] * ty[j];
}
if (2 * temp < totalarea)
{
continue;
}
int lx = x[(i + n - 1) % n], ly = y[(i + n - 1) % n];
int a = x[i] - lx, b = y[i] - ly;
int la = 0, lb = 0;
for (int j = 0; j < len; j++)
{
if (j < len - 2)
{
la += tx[j] * ty[j + 1] - tx[j + 1] * ty[j];
}
else if (j == len - 2)
{
//la+=lx*ly-ly*lx;
lb += lx * b - ly * a;
}
else
{
la += lx * ty[0] - ly * tx[0];
lb += a * ty[0] - b * tx[0];
}
}
la = (totalarea - 2 * la);
int nx = lx * 2 * lb + a * la;
int fx = 2 * lb;
int d = GCD(nx, fx);
nx /= d;
fx /= d;
if (fx < 0)
{
nx *= -1;
fx *= -1;
}
printf("(%d/%d),", nx, fx);
int ny = ly * 2 * lb + b * la;
int fy = 2 * lb;
int dd = GCD(ny, fy);
ny /= dd;
fy /= dd;
if (fy < 0)
{
ny *= -1;
fy *= -1;
}
printf("(%d/%d)\n", ny, fy);
break;
}
}
}
return 0;
}