L2-005 集合相似度
题目 L2-005 集合相似度
思路分析
代码实现
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
using PII = pair<int,int>;
using Pll = pair<ll,ll>;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
const int inf = 0x3f3f3f3f;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
vector<unordered_set<int>> sets(n+1);
for(int i=1;i<=n;i++){
int m,num;
cin>>m;
while(m--){
cin>>num;
sets[i].insert(num);
}
}
int k,a,b;cin>>k;
while(k--){
cin>>a>>b;
auto A=sets[a];
auto B=sets[b];
int nc=0;
for(auto x:A) nc+=B.count(x);
int nt = A.size() + B.size() - nc;
printf("%.2f%%\n",nc*100.0/nt);
}
return 0;
}
同类题型
视频讲解
⬅️ L2-004 这是二叉搜索树吗? 🏠 00-天梯赛 ➡️ L2-006 树的遍历
💬 评论