L2-005 集合相似度
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n,m,t; set<int>s[51];//此题主要考虑用set来解决 cin>>n; for(int i=1;i<=n;i++) { cin>>m; while(m--) { cin>>t; s[i].insert(t); } } int k,a,b; cin>>k; int numsame=0; double sum=0; while(k--) { numsame=0; cin>>a>>b; set<int>::iterator j; //见后文补充知识 for(j=s[a].begin();j!=s[a].end();j++) { if(s[b].count(*j)) numsame++; } sum=(numsame*100)/(s[a].size()+s[b].size()-numsame); printf("%.2lf%%\n", numsame * 100.0 / (s[a].size() + s[b].size() - numsame)); } return 0; }
标签:int,cin,L2,005,集合,numsame,size From: https://www.cnblogs.com/cornfield/p/17083467.html