-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy path159B - Matchmaker.cpp
More file actions
89 lines (79 loc) · 1.59 KB
/
Copy path159B - Matchmaker.cpp
File metadata and controls
89 lines (79 loc) · 1.59 KB
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
//4192310 Jul 28, 2013 5:58:29 AM fuwutu 159B - Matchmaker GNU C++0x Accepted 342 ms 1500 KB
#include <cstdio>
#include <algorithm>
using namespace std;
struct marker
{
int ax;
int by;
};
bool cmp(const marker& left, const marker& right)
{
return (left.by < right.by)
|| (left.by == right.by && left.ax < right.ax);
}
int main()
{
marker markers[100000], caps[100000];
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
{
scanf("%d%d", &markers[i].ax, &markers[i].by);
}
for (int i = 0; i < m; ++i)
{
scanf("%d%d", &caps[i].ax, &caps[i].by);
}
sort(markers, markers + n, cmp);
sort(caps, caps + m, cmp);
int u(0);
for (int i = 0, j = 0; i < n && j < m; )
{
if (markers[i].by < caps[j].by)
{
++i;
}
else if (markers[i].by > caps[j].by)
{
++j;
}
else
{
++u;
++i;
++j;
}
}
int v(0);
for (int i = 0, j = 0; i < n && j < m; )
{
if (markers[i].by < caps[j].by)
{
++i;
}
else if (markers[i].by > caps[j].by)
{
++j;
}
else
{
if (markers[i].ax < caps[j].ax)
{
++i;
}
else if (markers[i].ax > caps[j].ax)
{
++j;
}
else
{
++v;
++i;
++j;
}
}
}
printf("%d %d\n", u, v);
return 0;
}