-
Notifications
You must be signed in to change notification settings - Fork 34
/
1184-Marriage-Media.cpp
100 lines (68 loc) · 1.24 KB
/
1184-Marriage-Media.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n;
int m;
struct node
{
int age;
int height;
int divorce;
};
node men[60];
node women[60];
int seen[60];
int husband[60];
int ok(int i, int j)
{
if((men[i].divorce == women[j].divorce) and (abs(men[i].height - women[j].height) <= 12) and (abs(men[i].age - women[j].age) <= 5)) {
return true;
}
return false;
}
int bpm(int manId)
{
for (int i = 0; i < m; i++) {
if(ok(manId, i)) {
if(seen[i])
continue;
seen[i] = 1;
if(husband[i] < 0 or bpm(husband[i])) {
husband[i] = manId;
return true;
}
}
}
return false;
}
int main()
{
int t;
int count;
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%d", &n);
scanf("%d", &m);
for (int i = 0; i < n; i++) {
scanf("%d", &men[i].height);
scanf("%d", &men[i].age);
scanf("%d", &men[i].divorce);
}
for (int i = 0; i < m; i++) {
scanf("%d", &women[i].height);
scanf("%d", &women[i].age);
scanf("%d", &women[i].divorce);
}
memset(husband, -1, sizeof husband);
count = 0;
for (int i = 0; i < n; i++) {
memset(seen, 0, sizeof seen);
if(bpm(i)) {
count++;
}
}
printf("Case %d: %d\n", cs, count);
}
}