L2-005 集合相似度 (25 分)
摘要
Title: L2-005 集合相似度 (25 分)
Tag: set
Memory Limit: 64 MB
Time Limit: 1000 ms
Powered by:NEFU AB-IN
L2-005 集合相似度 (25 分)
-
题意
见原题
-
思路
即求去重后的两个集合,分子是两个集合的交集,分母是两个集合并集减去交集
ps: %的转义是两个% -
代码
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/*
* @Author: NEFU AB-IN
* @Date: 2022-04-20 12:16:10
* @FilePath: \ACM\GPLT\L2-005.CPP
* @LastEditTime: 2022-04-20 12:24:45
*/
using namespace std;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int N = 60;
set<int> s[N];
int n;
signed main()
{
IOS;
cin >> n;
for (int i = 1; i <= n; ++i)
{
int m;
cin >> m;
for (int j = 1; j <= m; ++j)
{
int x;
cin >> x;
s[i].insert(x);
}
}
int q;
cin >> q;
while (q--)
{
int a, b, cnt = 0;
cin >> a >> b;
for (auto x : s[a])
{
if (s[b].find(x) != s[b].end())
cnt += 1;
}
printf("%.2lf%%\n", 100.0 * cnt / (SZ(s[a]) + SZ(s[b]) - cnt));
}
return 0;
}