forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10167.cpp
66 lines (60 loc) · 1.07 KB
/
10167.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
#include <bits/stdc++.h>
using namespace std;
int n;
struct point
{
int x, y;
point() {}
point(const int &X, const int &Y) : x(X), y(Y) {}
};
struct line
{
int a, b;
line() {}
line(const int &A, const int &B) : a(A), b(B) {}
};
// positive if p is to the left of line l
// negative if p is to the right of line l
// zero if p is collinear with line l
int cross(const point &p, const line &l)
{
point q;
q.x = l.b;
q.y = -l.a;
return (p.x * q.y - q.x * p.y);
}
bool check(const vector<point> &c, const line &l)
{
int left = 0, right = 0;
for (int i = 0; i < 2 * n; ++i)
{
int t = cross(c[i], l);
left += (t > 0);
right += (t < 0);
}
return (left == n && right == n);
}
int main()
{
while (cin >> n && n)
{
vector<point> cherry(2 * n);
for (int i = 0; i < 2 * n; ++i)
{
cin >> cherry[i].x >> cherry[i].y;
}
bool found = false;
for (int i = -500; i <= 500 && !found; ++i)
{
for (int j = -500; j <= 500 && !found; ++j)
{
if (check(cherry, line(i, j)))
{
cout << i << " " << j << endl;
found = true;
}
}
}
}
return 0;
}