// Autor: Frane Kurtovic
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
using namespace std;
#define x first
#define y second
typedef long long llint;
typedef pair<llint, llint> point;
point operator+(const point &l, const point &r) {
return point(l.first+r.first, l.second+r.second);
}
point operator-(const point &l, const point &r) {
return point(l.first-r.first, l.second-r.second);
}
llint ccw(const point &a, const point &b, const point &c) {
point p1 = b-a;
point p2 = c-a;
return p1.first*p2.second - p1.second*p2.first;
}
bool out(const point &s, const point &e, const point &P) {
return ccw(s, e, P) < 0;
}
bool out_or_on(const point &s, const point &e, const point &P) {
return ccw(s, e, P) <= 0;
}
const int MAX_N = 100010;
point ships[MAX_N]; int n;
vector <point> poly; int m; // u ccw smjeru zadan
pair<int, int> find_tangent(const point &P) {
point prev = poly[m-1];
int left_t = -1, right_t = -1;
for (int i = 0; i < m; i++) {
point curr = poly[i];
point next = poly[i+1];
if (out(prev, curr, P) && !out(curr, next, P)) {
// desna tangenta
assert (right_t == -1);
right_t = i;
}
if (!out(prev, curr, P) && out(curr, next, P)) {
// lijeva tangenta
assert (left_t == -1);
left_t = i;
}
prev = curr;
}
assert (left_t != -1);
assert (right_t != -1);
return {left_t, right_t};
}
int prev(int x) {
if (x == 0) return m-1;
return x-1;
}
int next(int x) {
return (x+1)%m;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &ships[i].x, &ships[i].y);
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
point curr;
scanf("%lld %lld", &curr.x, &curr.y);
poly.push_back(curr);
}
poly.push_back(poly.front());
point P = ships[0];
auto tangents = find_tangent(P);
int l_tangent = tangents.first, r_tangent = tangents.second;
point l = P, r = P; // tocka iz koje ide najlijevija tangenta
set <point> s;
for (int i = 1; i < n; i++) {
point T = ships[i];
if (ccw(P, poly[tangents.first], ships[i]) >= 0 || ccw(P, poly[tangents.second], ships[i]) <= 0) {
s.insert(ships[i]);
} else if (ccw(P, poly[tangents.first], ships[i]) < 0 &&
ccw(P, poly[tangents.second], ships[i]) > 0 &&
ccw(poly[tangents.first], poly[tangents.second], ships[i]) <= 0) {
// izmedju dvije tangente i otoka
s.insert(ships[i]);
}
if (ccw(P, poly[tangents.first], T) >= 0) {
// strana lijeve tangente
while(true) {
int next_e = prev(l_tangent);
if (out_or_on(poly[next_e], poly[l_tangent], T)) {
l_tangent = next_e;
l = T;
} else {
break;
}
}
if (ccw(l, poly[l_tangent], T) > 0) {
l = T;
}
}
if (ccw(P, poly[tangents.second], T) <= 0) {
// strana desne tangente
while(true) {
int next_e = next(r_tangent);
if (out_or_on(poly[r_tangent], poly[next_e], T)) {
r_tangent = next_e;
r = T;
} else {
break;
}
}
if (ccw(r, poly[r_tangent], T) < 0) {
r = T;
}
}
}
for (int i = 0; i < n; i++) {
point p = ships[i];
if (ccw(l, poly[l_tangent], p) >= 0) {
s.insert(p);
} else if (ccw(l, P, p) >= 0 && ccw(P, poly[l_tangent], p) >= 0) {
s.insert(p);
}
if (ccw(r, poly[r_tangent], p) <= 0) {
s.insert(p);
} else if (ccw(P, r, p) >= 0 && ccw(poly[r_tangent], P, p) >= 0) {
s.insert(p);
}
}
s.erase(P);
printf("%lu\n", s.size());
return 0;
}
Compilation message
relay.cpp: In function 'int main()':
relay.cpp:77:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
relay.cpp:79:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &ships[i].x, &ships[i].y);
^
relay.cpp:81:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &m);
^
relay.cpp:84:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &curr.x, &curr.y);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2740 KB |
Output is correct |
2 |
Correct |
0 ms |
2740 KB |
Output is correct |
3 |
Correct |
0 ms |
2740 KB |
Output is correct |
4 |
Correct |
0 ms |
2740 KB |
Output is correct |
5 |
Correct |
0 ms |
2740 KB |
Output is correct |
6 |
Correct |
0 ms |
2740 KB |
Output is correct |
7 |
Correct |
0 ms |
2740 KB |
Output is correct |
8 |
Correct |
0 ms |
2740 KB |
Output is correct |
9 |
Correct |
0 ms |
2740 KB |
Output is correct |
10 |
Correct |
0 ms |
2740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2740 KB |
Output is correct |
2 |
Correct |
0 ms |
2740 KB |
Output is correct |
3 |
Correct |
0 ms |
2740 KB |
Output is correct |
4 |
Correct |
0 ms |
2740 KB |
Output is correct |
5 |
Correct |
0 ms |
2740 KB |
Output is correct |
6 |
Correct |
0 ms |
2740 KB |
Output is correct |
7 |
Correct |
0 ms |
2740 KB |
Output is correct |
8 |
Correct |
0 ms |
2740 KB |
Output is correct |
9 |
Correct |
0 ms |
2740 KB |
Output is correct |
10 |
Correct |
0 ms |
2740 KB |
Output is correct |
11 |
Correct |
0 ms |
2880 KB |
Output is correct |
12 |
Correct |
0 ms |
2880 KB |
Output is correct |
13 |
Correct |
0 ms |
2880 KB |
Output is correct |
14 |
Correct |
0 ms |
2880 KB |
Output is correct |
15 |
Correct |
0 ms |
2880 KB |
Output is correct |
16 |
Correct |
0 ms |
2880 KB |
Output is correct |
17 |
Correct |
0 ms |
2880 KB |
Output is correct |
18 |
Correct |
3 ms |
3012 KB |
Output is correct |
19 |
Correct |
0 ms |
2880 KB |
Output is correct |
20 |
Correct |
0 ms |
2880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2740 KB |
Output is correct |
2 |
Correct |
0 ms |
2740 KB |
Output is correct |
3 |
Correct |
0 ms |
2740 KB |
Output is correct |
4 |
Correct |
0 ms |
2740 KB |
Output is correct |
5 |
Correct |
0 ms |
2740 KB |
Output is correct |
6 |
Correct |
0 ms |
2740 KB |
Output is correct |
7 |
Correct |
0 ms |
2740 KB |
Output is correct |
8 |
Correct |
0 ms |
2740 KB |
Output is correct |
9 |
Correct |
0 ms |
2740 KB |
Output is correct |
10 |
Correct |
0 ms |
2740 KB |
Output is correct |
11 |
Correct |
36 ms |
5380 KB |
Output is correct |
12 |
Correct |
43 ms |
5380 KB |
Output is correct |
13 |
Correct |
59 ms |
8020 KB |
Output is correct |
14 |
Correct |
46 ms |
5380 KB |
Output is correct |
15 |
Correct |
46 ms |
4324 KB |
Output is correct |
16 |
Correct |
49 ms |
4324 KB |
Output is correct |
17 |
Correct |
83 ms |
8020 KB |
Output is correct |
18 |
Correct |
89 ms |
7888 KB |
Output is correct |
19 |
Correct |
79 ms |
7756 KB |
Output is correct |
20 |
Correct |
53 ms |
5644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2740 KB |
Output is correct |
2 |
Correct |
0 ms |
2740 KB |
Output is correct |
3 |
Correct |
0 ms |
2740 KB |
Output is correct |
4 |
Correct |
0 ms |
2740 KB |
Output is correct |
5 |
Correct |
0 ms |
2740 KB |
Output is correct |
6 |
Correct |
0 ms |
2740 KB |
Output is correct |
7 |
Correct |
0 ms |
2740 KB |
Output is correct |
8 |
Correct |
0 ms |
2740 KB |
Output is correct |
9 |
Correct |
0 ms |
2740 KB |
Output is correct |
10 |
Correct |
0 ms |
2740 KB |
Output is correct |
11 |
Correct |
0 ms |
2880 KB |
Output is correct |
12 |
Correct |
0 ms |
2880 KB |
Output is correct |
13 |
Correct |
0 ms |
2880 KB |
Output is correct |
14 |
Correct |
0 ms |
2880 KB |
Output is correct |
15 |
Correct |
0 ms |
2880 KB |
Output is correct |
16 |
Correct |
0 ms |
2880 KB |
Output is correct |
17 |
Correct |
0 ms |
2880 KB |
Output is correct |
18 |
Correct |
3 ms |
3012 KB |
Output is correct |
19 |
Correct |
0 ms |
2880 KB |
Output is correct |
20 |
Correct |
0 ms |
2880 KB |
Output is correct |
21 |
Correct |
36 ms |
5380 KB |
Output is correct |
22 |
Correct |
43 ms |
5380 KB |
Output is correct |
23 |
Correct |
59 ms |
8020 KB |
Output is correct |
24 |
Correct |
46 ms |
5380 KB |
Output is correct |
25 |
Correct |
46 ms |
4324 KB |
Output is correct |
26 |
Correct |
49 ms |
4324 KB |
Output is correct |
27 |
Correct |
83 ms |
8020 KB |
Output is correct |
28 |
Correct |
89 ms |
7888 KB |
Output is correct |
29 |
Correct |
79 ms |
7756 KB |
Output is correct |
30 |
Correct |
53 ms |
5644 KB |
Output is correct |
31 |
Correct |
73 ms |
7376 KB |
Output is correct |
32 |
Correct |
79 ms |
7376 KB |
Output is correct |
33 |
Correct |
89 ms |
8332 KB |
Output is correct |
34 |
Correct |
69 ms |
8596 KB |
Output is correct |
35 |
Correct |
76 ms |
7012 KB |
Output is correct |
36 |
Correct |
76 ms |
6484 KB |
Output is correct |
37 |
Correct |
116 ms |
8728 KB |
Output is correct |
38 |
Correct |
119 ms |
9916 KB |
Output is correct |
39 |
Correct |
63 ms |
6352 KB |
Output is correct |
40 |
Correct |
69 ms |
6616 KB |
Output is correct |