-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcq_20.cpp
More file actions
64 lines (61 loc) · 2.12 KB
/
Copy pathcq_20.cpp
File metadata and controls
64 lines (61 loc) · 2.12 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
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
struct bird {
string s;
double a, b, c, d;
};
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t; cin >> t;
while (t--) {
int x, y; cin >> x >> y;
bird known[x], qry[y];
for (int i = 0; i < x; i++) {
cin >> known[i].s >> known[i].a >> known[i].b >> known[i].c >> known[i].d;
}
for (int i = 0; i < y; i++) {
cin >> qry[i].a >> qry[i].b >> qry[i].c >> qry[i].d;
pair<double, string> kvals[x];
for (int j = 0; j < x; j++) {
double d = (known[j].a - qry[i].a) * (known[j].a - qry[i].a) + (known[j].b - qry[i].b) * (known[j].b - qry[i].b) + (known[j].c - qry[i].c) * (known[j].c - qry[i].c) + (known[j].d - qry[i].d) *(known[j].d - qry[i].d) ;
kvals[j] = make_pair(d, known[j].s);
}
sort(kvals, kvals + x);
map<string, int> cnt;
for (int j = 0; j < 5; j++) {
cnt[kvals[j].second]++;
}
int mxv = -1, cvm = 0;
string best = "";
for (map<string, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
int cv = it -> second;
if (cv > mxv) {
mxv = cv;
best = it -> first;
cvm = 1;
} else if (cv == mxv) cvm++;
}
int ix = 5;
if (cvm > 1) {
while (true) {
mxv = -1;
cvm = 0;
cnt[kvals[ix++].second]++;
for (map<string, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
int cv = it -> second;
if (cv > mxv) {
mxv = cv;
best = it -> first;
cvm = 1;
} else if (cv == mxv) cvm++;
}
if (cvm == 1) break;
}
}
cout << best << endl;
}
}
return 0;
}