天天写写水题总感觉不太好

题目链接 L2-005 集合相似度 (25 分)

#include <bits/stdc++.h>
using namespace std;

set<int> s[55];
int num,n,m,mix,diff,tmp;
int main() {

	scanf("%d", &num);
	for(int i = 1; i <= num; i++) {
		scanf("%d", &n);
		for(int j = 0; j < n; j++) {
			scanf("%d", &m);
			s[i].insert(m);
		}
	}
	scanf("%d", &num);
	while(num--) {
		scanf("%d %d", &n, &m);
		int count = 0;
		if(s[n].size() > s[m].size()) {
			tmp = n;
			n = m;
			m = tmp;
		}
		for(auto item : s[n]) {
			if(s[m].find(item) != s[m].end())
				count++;
		}
		mix = s[n].size() + s[m].size() - count;
		printf("%.2lf%\n", count * 1.0 / mix * 100);
	}
}