#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
struct point {
int x, y, f, i;
} p[3010];
int n, ans[1010][2];
ll cross(const point& a,const point& b,const point& c) {
return (ll)(b.x-a.x)*(c.y-a.y)-(ll)(b.y-a.y)*(c.x-a.x);
}
void solve(int l, int r) {
if(r-l+1<3) return;
if(r-l+1==3) {
int i,j,k=0;
for(i=l;i<=r;i++) if(p[i].f==2)
for(j=l;j<=r;j++)
if(i!=j) ans[p[i].i][k++]=p[j].i;
return;
}
int j=-1;
int i;
for(i=l;i<=r;i++)
if(j==-1||p[i].x<p[j].x||(p[i].x==p[j].x&&p[i].y<p[j].y)) j=i;
swap(p[j],p[l]);
sort(p+l+1,p+r+1,[&](const point& a,const point& b) {
return cross(p[l], a, b)>0;
});
if(p[l].f==-1 && (p[l+1].f==2||p[r].f==2)) {
if(p[l+1].f==2) swap(p[l], p[l+1]);
else swap(p[l], p[r]);
sort(p+l+1,p+r+1,[&](const point& a,const point& b) {
return cross(p[l], a, b)>0;
});
}
int sum=p[l].f;
for(i=l+1;i<=r;i++){
sum+=p[i].f;
if(!sum) {
if(p[l].f==2) {
ans[p[l].i][0]=p[i].i;
ans[p[l].i][1]=p[i-1].i;
solve(l+1,i-2);
solve(i+1,r);
return;
} else {
if(i<r) {
solve(l,i);
solve(i+1,r);
return;
} else {
sum=p[l].f;
for(j=r;j>l;j--) {
sum+=p[j].f;
if(!sum) {
swap(p[l],p[j-1]);
solve(l,j-2);
solve(j-1,r);
return;
}
}
}
}
}
}
}
int main() {
scanf("%d",&n);
for(int i=0;i<n;i++) {
scanf("%d%d",&p[i].x,&p[i].y);
p[i].f=2; p[i].i=i;
}
for(int i=0;i<n+n;i++) {
scanf("%d%d",&p[n+i].x,&p[n+i].y);
p[n+i].f=-1; p[n+i].i=i;
}
solve(0,3*n-1);
for(int i=0;i<n;i++) printf("%d %d\n",ans[i][0]+1,ans[i][1]+1);
return 0;
}
Compilation message
laser.cpp: In function 'int main()':
laser.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
laser.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&p[i].x,&p[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
laser.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&p[n+i].x,&p[n+i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
360 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
256 KB |
Output is correct |
34 |
Correct |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
376 KB |
Output is correct |
43 |
Correct |
3 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
3 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
380 KB |
Output is correct |
49 |
Correct |
3 ms |
376 KB |
Output is correct |
50 |
Correct |
3 ms |
376 KB |
Output is correct |
51 |
Correct |
3 ms |
376 KB |
Output is correct |
52 |
Correct |
3 ms |
376 KB |
Output is correct |
53 |
Correct |
3 ms |
376 KB |
Output is correct |
54 |
Correct |
3 ms |
376 KB |
Output is correct |
55 |
Correct |
3 ms |
376 KB |
Output is correct |
56 |
Correct |
3 ms |
376 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
2 ms |
376 KB |
Output is correct |
59 |
Correct |
2 ms |
376 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
2 ms |
376 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
63 |
Correct |
3 ms |
376 KB |
Output is correct |
64 |
Correct |
3 ms |
376 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Correct |
3 ms |
376 KB |
Output is correct |
67 |
Correct |
3 ms |
376 KB |
Output is correct |
68 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
360 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
256 KB |
Output is correct |
34 |
Correct |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
376 KB |
Output is correct |
43 |
Correct |
3 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
3 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
380 KB |
Output is correct |
49 |
Correct |
3 ms |
376 KB |
Output is correct |
50 |
Correct |
3 ms |
376 KB |
Output is correct |
51 |
Correct |
3 ms |
376 KB |
Output is correct |
52 |
Correct |
3 ms |
376 KB |
Output is correct |
53 |
Correct |
3 ms |
376 KB |
Output is correct |
54 |
Correct |
3 ms |
376 KB |
Output is correct |
55 |
Correct |
3 ms |
376 KB |
Output is correct |
56 |
Correct |
3 ms |
376 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
2 ms |
376 KB |
Output is correct |
59 |
Correct |
2 ms |
376 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
2 ms |
376 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
63 |
Correct |
3 ms |
376 KB |
Output is correct |
64 |
Correct |
3 ms |
376 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Correct |
3 ms |
376 KB |
Output is correct |
67 |
Correct |
3 ms |
376 KB |
Output is correct |
68 |
Correct |
3 ms |
376 KB |
Output is correct |
69 |
Correct |
24 ms |
504 KB |
Output is correct |
70 |
Correct |
23 ms |
504 KB |
Output is correct |
71 |
Correct |
16 ms |
504 KB |
Output is correct |
72 |
Correct |
14 ms |
424 KB |
Output is correct |
73 |
Correct |
25 ms |
504 KB |
Output is correct |
74 |
Correct |
22 ms |
504 KB |
Output is correct |
75 |
Correct |
14 ms |
376 KB |
Output is correct |
76 |
Correct |
18 ms |
464 KB |
Output is correct |
77 |
Correct |
16 ms |
504 KB |
Output is correct |
78 |
Correct |
18 ms |
504 KB |
Output is correct |
79 |
Correct |
115 ms |
504 KB |
Output is correct |
80 |
Correct |
117 ms |
512 KB |
Output is correct |
81 |
Correct |
117 ms |
512 KB |
Output is correct |
82 |
Correct |
137 ms |
504 KB |
Output is correct |
83 |
Correct |
121 ms |
508 KB |
Output is correct |
84 |
Correct |
123 ms |
476 KB |
Output is correct |
85 |
Correct |
122 ms |
636 KB |
Output is correct |
86 |
Correct |
120 ms |
604 KB |
Output is correct |
87 |
Correct |
12 ms |
504 KB |
Output is correct |
88 |
Correct |
9 ms |
376 KB |
Output is correct |
89 |
Correct |
8 ms |
504 KB |
Output is correct |
90 |
Correct |
19 ms |
504 KB |
Output is correct |
91 |
Correct |
17 ms |
376 KB |
Output is correct |
92 |
Correct |
16 ms |
504 KB |
Output is correct |
93 |
Correct |
12 ms |
368 KB |
Output is correct |
94 |
Correct |
19 ms |
460 KB |
Output is correct |
95 |
Correct |
27 ms |
504 KB |
Output is correct |
96 |
Correct |
30 ms |
376 KB |
Output is correct |
97 |
Correct |
32 ms |
376 KB |
Output is correct |
98 |
Correct |
25 ms |
508 KB |
Output is correct |