#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;
struct point {
point() {
x = y = t = 0;
}
point(long long x_, long long y_, int t_) {
x = x_; y = y_; t = t_;
}
long long x, y;
int t;
bool operator <(const point &t) const {
return x * t.y > y * t.x;
}
point operator -(point &a) {
return point(x - a.x, y - a.y, t);
}
}P[3020];
int R[1020][2];
int ccw(point &a, point &b, point &c)
{
long long p = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
if (p > 0) return 1;
if (p < 0) return -1;
return 0;
}
int ccw(int i, int j, int k)
{
return ccw(P[i], P[j], P[k]);
}
void match(vector<int> &p)
{
if (p.empty()) return;
vector<point> u;
for (int i = 0; i < p.size(); i++) {
u.push_back(P[p[i]]);
u.back().t = p[i];
}
for (int i = 1; i < u.size(); i++) {
if (u[0].y > u[i].y || (u[0].y == u[i].y && u[0].x > u[i].x)) {
swap(u[0], u[i]);
}
}
for (int i = (int)u.size() - 1; i >= 0; i--) u[i] = u[i] - u[0];
sort(u.begin() + 1, u.end());
int s = -1, f = u[0].t;
u.erase(u.begin());
if (P[f].t) s = f;
else if (P[u[0].t].t) s = u[0].t;
else if (P[u.back().t].t) s = u.back().t;
if (s != -1) {
if (s != f) {
u.clear();
for (int i = 0; i < p.size(); i++) if (p[i] != s) {
u.push_back(P[p[i]] - P[s]);
u.back().t = p[i];
}
sort(u.begin(), u.end());
}
int b = 0, obj = -1;
vector<int> g;
for (int j = 0; j < u.size(); j++) {
b += P[u[j].t].t ? +2 : -1;
if (b == obj) {
R[s][-obj - 1] = u[j].t;
match(g);
g.clear();
obj--;
if (obj < -2) obj = -2000000;
}
else {
g.push_back(u[j].t);
}
}
match(g);
return;
}
for (int k = 0; k < 2; k++) {
int b = 0;
vector<int> g;
for (int j = 0; j < u.size(); j++) {
b += P[u[j].t].t ? +2 : -1;
g.push_back(u[j].t);
if (b == 0) {
match(g);
g.clear();
for (int i = j + 1; i < u.size(); i++) g.push_back(u[i].t);
g.push_back(f);
match(g);
return;
}
}
reverse(u.begin(), u.end());
}
}
int main()
{
int N; scanf("%d", &N);
vector<int> pt;
for (int i = 0; i < N * 3; i++) {
scanf("%lld %lld", &P[i].x, &P[i].y);
P[i].t = i < N;
pt.push_back(i);
}
match(pt);
for (int i = 0; i < N; i++) printf("%d %d\n", R[i][0] - N + 1, R[i][1] - N + 1);
return 0;
}
Compilation message
laser.cpp: In function 'void match(std::vector<int>&)':
laser.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < p.size(); i++) {
^
laser.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < u.size(); i++) {
^
laser.cpp:65:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < p.size(); i++) if (p[i] != s) {
^
laser.cpp:75:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < u.size(); j++) {
^
laser.cpp:96:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < u.size(); j++) {
^
laser.cpp:103:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = j + 1; i < u.size(); i++) g.push_back(u[i].t);
^
laser.cpp: In function 'int main()':
laser.cpp:115:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int N; scanf("%d", &N);
^
laser.cpp:119:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &P[i].x, &P[i].y);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1252 KB |
Output is correct |
2 |
Correct |
0 ms |
1252 KB |
Output is correct |
3 |
Correct |
0 ms |
1252 KB |
Output is correct |
4 |
Correct |
0 ms |
1252 KB |
Output is correct |
5 |
Correct |
0 ms |
1252 KB |
Output is correct |
6 |
Correct |
0 ms |
1252 KB |
Output is correct |
7 |
Correct |
0 ms |
1252 KB |
Output is correct |
8 |
Correct |
0 ms |
1252 KB |
Output is correct |
9 |
Correct |
0 ms |
1252 KB |
Output is correct |
10 |
Correct |
0 ms |
1252 KB |
Output is correct |
11 |
Correct |
0 ms |
1252 KB |
Output is correct |
12 |
Correct |
0 ms |
1252 KB |
Output is correct |
13 |
Correct |
0 ms |
1252 KB |
Output is correct |
14 |
Correct |
0 ms |
1252 KB |
Output is correct |
15 |
Correct |
0 ms |
1252 KB |
Output is correct |
16 |
Correct |
0 ms |
1252 KB |
Output is correct |
17 |
Correct |
0 ms |
1252 KB |
Output is correct |
18 |
Correct |
0 ms |
1252 KB |
Output is correct |
19 |
Correct |
0 ms |
1252 KB |
Output is correct |
20 |
Correct |
0 ms |
1252 KB |
Output is correct |
21 |
Correct |
0 ms |
1252 KB |
Output is correct |
22 |
Correct |
0 ms |
1252 KB |
Output is correct |
23 |
Correct |
0 ms |
1252 KB |
Output is correct |
24 |
Correct |
0 ms |
1252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1520 KB |
Output is correct |
2 |
Correct |
0 ms |
1384 KB |
Output is correct |
3 |
Correct |
0 ms |
1388 KB |
Output is correct |
4 |
Correct |
0 ms |
1388 KB |
Output is correct |
5 |
Correct |
0 ms |
1384 KB |
Output is correct |
6 |
Correct |
0 ms |
1388 KB |
Output is correct |
7 |
Correct |
0 ms |
1252 KB |
Output is correct |
8 |
Correct |
0 ms |
1392 KB |
Output is correct |
9 |
Correct |
0 ms |
1388 KB |
Output is correct |
10 |
Correct |
0 ms |
1384 KB |
Output is correct |
11 |
Correct |
0 ms |
1924 KB |
Output is correct |
12 |
Correct |
0 ms |
1488 KB |
Output is correct |
13 |
Correct |
0 ms |
1516 KB |
Output is correct |
14 |
Correct |
0 ms |
1924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1252 KB |
Output is correct |
2 |
Correct |
0 ms |
1252 KB |
Output is correct |
3 |
Correct |
0 ms |
1252 KB |
Output is correct |
4 |
Correct |
0 ms |
1252 KB |
Output is correct |
5 |
Correct |
0 ms |
1252 KB |
Output is correct |
6 |
Correct |
0 ms |
1252 KB |
Output is correct |
7 |
Correct |
0 ms |
1252 KB |
Output is correct |
8 |
Correct |
0 ms |
1252 KB |
Output is correct |
9 |
Correct |
0 ms |
1252 KB |
Output is correct |
10 |
Correct |
0 ms |
1252 KB |
Output is correct |
11 |
Correct |
0 ms |
1252 KB |
Output is correct |
12 |
Correct |
0 ms |
1252 KB |
Output is correct |
13 |
Correct |
0 ms |
1252 KB |
Output is correct |
14 |
Correct |
0 ms |
1252 KB |
Output is correct |
15 |
Correct |
0 ms |
1252 KB |
Output is correct |
16 |
Correct |
0 ms |
1252 KB |
Output is correct |
17 |
Correct |
0 ms |
1252 KB |
Output is correct |
18 |
Correct |
0 ms |
1252 KB |
Output is correct |
19 |
Correct |
0 ms |
1252 KB |
Output is correct |
20 |
Correct |
0 ms |
1252 KB |
Output is correct |
21 |
Correct |
0 ms |
1252 KB |
Output is correct |
22 |
Correct |
0 ms |
1252 KB |
Output is correct |
23 |
Correct |
0 ms |
1252 KB |
Output is correct |
24 |
Correct |
0 ms |
1252 KB |
Output is correct |
25 |
Correct |
0 ms |
1520 KB |
Output is correct |
26 |
Correct |
0 ms |
1384 KB |
Output is correct |
27 |
Correct |
0 ms |
1388 KB |
Output is correct |
28 |
Correct |
0 ms |
1388 KB |
Output is correct |
29 |
Correct |
0 ms |
1384 KB |
Output is correct |
30 |
Correct |
0 ms |
1388 KB |
Output is correct |
31 |
Correct |
0 ms |
1252 KB |
Output is correct |
32 |
Correct |
0 ms |
1392 KB |
Output is correct |
33 |
Correct |
0 ms |
1388 KB |
Output is correct |
34 |
Correct |
0 ms |
1384 KB |
Output is correct |
35 |
Correct |
0 ms |
1924 KB |
Output is correct |
36 |
Correct |
0 ms |
1488 KB |
Output is correct |
37 |
Correct |
0 ms |
1516 KB |
Output is correct |
38 |
Correct |
0 ms |
1924 KB |
Output is correct |
39 |
Correct |
0 ms |
1384 KB |
Output is correct |
40 |
Correct |
0 ms |
1384 KB |
Output is correct |
41 |
Correct |
0 ms |
1384 KB |
Output is correct |
42 |
Correct |
0 ms |
1384 KB |
Output is correct |
43 |
Correct |
0 ms |
1384 KB |
Output is correct |
44 |
Correct |
0 ms |
1384 KB |
Output is correct |
45 |
Correct |
0 ms |
1392 KB |
Output is correct |
46 |
Correct |
0 ms |
1384 KB |
Output is correct |
47 |
Correct |
0 ms |
1516 KB |
Output is correct |
48 |
Correct |
0 ms |
1384 KB |
Output is correct |
49 |
Correct |
0 ms |
1620 KB |
Output is correct |
50 |
Correct |
0 ms |
1488 KB |
Output is correct |
51 |
Correct |
0 ms |
1780 KB |
Output is correct |
52 |
Correct |
0 ms |
1780 KB |
Output is correct |
53 |
Correct |
0 ms |
1924 KB |
Output is correct |
54 |
Correct |
0 ms |
1924 KB |
Output is correct |
55 |
Correct |
0 ms |
1924 KB |
Output is correct |
56 |
Correct |
0 ms |
1924 KB |
Output is correct |
57 |
Correct |
0 ms |
1252 KB |
Output is correct |
58 |
Correct |
0 ms |
1384 KB |
Output is correct |
59 |
Correct |
0 ms |
1392 KB |
Output is correct |
60 |
Correct |
0 ms |
1384 KB |
Output is correct |
61 |
Correct |
0 ms |
1384 KB |
Output is correct |
62 |
Correct |
0 ms |
1384 KB |
Output is correct |
63 |
Correct |
0 ms |
1384 KB |
Output is correct |
64 |
Correct |
0 ms |
1516 KB |
Output is correct |
65 |
Correct |
0 ms |
1384 KB |
Output is correct |
66 |
Correct |
0 ms |
1384 KB |
Output is correct |
67 |
Correct |
0 ms |
1384 KB |
Output is correct |
68 |
Correct |
0 ms |
1392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1252 KB |
Output is correct |
2 |
Correct |
0 ms |
1252 KB |
Output is correct |
3 |
Correct |
0 ms |
1252 KB |
Output is correct |
4 |
Correct |
0 ms |
1252 KB |
Output is correct |
5 |
Correct |
0 ms |
1252 KB |
Output is correct |
6 |
Correct |
0 ms |
1252 KB |
Output is correct |
7 |
Correct |
0 ms |
1252 KB |
Output is correct |
8 |
Correct |
0 ms |
1252 KB |
Output is correct |
9 |
Correct |
0 ms |
1252 KB |
Output is correct |
10 |
Correct |
0 ms |
1252 KB |
Output is correct |
11 |
Correct |
0 ms |
1252 KB |
Output is correct |
12 |
Correct |
0 ms |
1252 KB |
Output is correct |
13 |
Correct |
0 ms |
1252 KB |
Output is correct |
14 |
Correct |
0 ms |
1252 KB |
Output is correct |
15 |
Correct |
0 ms |
1252 KB |
Output is correct |
16 |
Correct |
0 ms |
1252 KB |
Output is correct |
17 |
Correct |
0 ms |
1252 KB |
Output is correct |
18 |
Correct |
0 ms |
1252 KB |
Output is correct |
19 |
Correct |
0 ms |
1252 KB |
Output is correct |
20 |
Correct |
0 ms |
1252 KB |
Output is correct |
21 |
Correct |
0 ms |
1252 KB |
Output is correct |
22 |
Correct |
0 ms |
1252 KB |
Output is correct |
23 |
Correct |
0 ms |
1252 KB |
Output is correct |
24 |
Correct |
0 ms |
1252 KB |
Output is correct |
25 |
Correct |
0 ms |
1520 KB |
Output is correct |
26 |
Correct |
0 ms |
1384 KB |
Output is correct |
27 |
Correct |
0 ms |
1388 KB |
Output is correct |
28 |
Correct |
0 ms |
1388 KB |
Output is correct |
29 |
Correct |
0 ms |
1384 KB |
Output is correct |
30 |
Correct |
0 ms |
1388 KB |
Output is correct |
31 |
Correct |
0 ms |
1252 KB |
Output is correct |
32 |
Correct |
0 ms |
1392 KB |
Output is correct |
33 |
Correct |
0 ms |
1388 KB |
Output is correct |
34 |
Correct |
0 ms |
1384 KB |
Output is correct |
35 |
Correct |
0 ms |
1924 KB |
Output is correct |
36 |
Correct |
0 ms |
1488 KB |
Output is correct |
37 |
Correct |
0 ms |
1516 KB |
Output is correct |
38 |
Correct |
0 ms |
1924 KB |
Output is correct |
39 |
Correct |
0 ms |
1384 KB |
Output is correct |
40 |
Correct |
0 ms |
1384 KB |
Output is correct |
41 |
Correct |
0 ms |
1384 KB |
Output is correct |
42 |
Correct |
0 ms |
1384 KB |
Output is correct |
43 |
Correct |
0 ms |
1384 KB |
Output is correct |
44 |
Correct |
0 ms |
1384 KB |
Output is correct |
45 |
Correct |
0 ms |
1392 KB |
Output is correct |
46 |
Correct |
0 ms |
1384 KB |
Output is correct |
47 |
Correct |
0 ms |
1516 KB |
Output is correct |
48 |
Correct |
0 ms |
1384 KB |
Output is correct |
49 |
Correct |
0 ms |
1620 KB |
Output is correct |
50 |
Correct |
0 ms |
1488 KB |
Output is correct |
51 |
Correct |
0 ms |
1780 KB |
Output is correct |
52 |
Correct |
0 ms |
1780 KB |
Output is correct |
53 |
Correct |
0 ms |
1924 KB |
Output is correct |
54 |
Correct |
0 ms |
1924 KB |
Output is correct |
55 |
Correct |
0 ms |
1924 KB |
Output is correct |
56 |
Correct |
0 ms |
1924 KB |
Output is correct |
57 |
Correct |
0 ms |
1252 KB |
Output is correct |
58 |
Correct |
0 ms |
1384 KB |
Output is correct |
59 |
Correct |
0 ms |
1392 KB |
Output is correct |
60 |
Correct |
0 ms |
1384 KB |
Output is correct |
61 |
Correct |
0 ms |
1384 KB |
Output is correct |
62 |
Correct |
0 ms |
1384 KB |
Output is correct |
63 |
Correct |
0 ms |
1384 KB |
Output is correct |
64 |
Correct |
0 ms |
1516 KB |
Output is correct |
65 |
Correct |
0 ms |
1384 KB |
Output is correct |
66 |
Correct |
0 ms |
1384 KB |
Output is correct |
67 |
Correct |
0 ms |
1384 KB |
Output is correct |
68 |
Correct |
0 ms |
1392 KB |
Output is correct |
69 |
Correct |
13 ms |
4324 KB |
Output is correct |
70 |
Correct |
13 ms |
3376 KB |
Output is correct |
71 |
Correct |
26 ms |
9104 KB |
Output is correct |
72 |
Correct |
13 ms |
4096 KB |
Output is correct |
73 |
Correct |
6 ms |
3384 KB |
Output is correct |
74 |
Correct |
13 ms |
6224 KB |
Output is correct |
75 |
Correct |
16 ms |
5296 KB |
Output is correct |
76 |
Correct |
19 ms |
7280 KB |
Output is correct |
77 |
Correct |
16 ms |
4600 KB |
Output is correct |
78 |
Correct |
13 ms |
3712 KB |
Output is correct |
79 |
Correct |
79 ms |
43684 KB |
Output is correct |
80 |
Correct |
66 ms |
39140 KB |
Output is correct |
81 |
Correct |
66 ms |
42580 KB |
Output is correct |
82 |
Correct |
59 ms |
28876 KB |
Output is correct |
83 |
Correct |
63 ms |
63152 KB |
Output is correct |
84 |
Correct |
66 ms |
63148 KB |
Output is correct |
85 |
Correct |
79 ms |
63152 KB |
Output is correct |
86 |
Correct |
66 ms |
63152 KB |
Output is correct |
87 |
Correct |
6 ms |
4168 KB |
Output is correct |
88 |
Correct |
6 ms |
5320 KB |
Output is correct |
89 |
Correct |
39 ms |
14924 KB |
Output is correct |
90 |
Correct |
3 ms |
2392 KB |
Output is correct |
91 |
Correct |
13 ms |
4984 KB |
Output is correct |
92 |
Correct |
13 ms |
3352 KB |
Output is correct |
93 |
Correct |
13 ms |
3940 KB |
Output is correct |
94 |
Correct |
9 ms |
4168 KB |
Output is correct |
95 |
Correct |
19 ms |
9800 KB |
Output is correct |
96 |
Correct |
13 ms |
4252 KB |
Output is correct |
97 |
Correct |
19 ms |
5596 KB |
Output is correct |
98 |
Correct |
19 ms |
6232 KB |
Output is correct |