-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathA1063.cpp
More file actions
41 lines (38 loc) · 928 Bytes
/
Copy pathA1063.cpp
File metadata and controls
41 lines (38 loc) · 928 Bytes
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
#include <cstdio>
#include <algorithm>
#include <set>
#define MAXN 50
using namespace std;
set<int> sets[MAXN + 5];
double get_similarity(int a, int b)
{
int intersection = 0;
if (sets[a].size() > sets[b].size()) swap(a, b);
for (set<int>::iterator it = sets[a].begin(); it != sets[a].end(); it++)
if (sets[b].find(*(it)) != sets[b].end()) intersection++;
return 100.0 * intersection / (sets[a].size() + sets[b].size() - intersection);
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int cnt, val;
scanf("%d", &cnt);
for (; cnt > 0; cnt--)
{
scanf("%d", &val);
sets[i].insert(val);
}
}
int queries;
scanf("%d", &queries);
for (int i = 0; i < queries; i++)
{
int a, b;
scanf("%d %d", &a, &b);
printf("%.1lf%\n", get_similarity(a, b));
}
return 0;
}