質問A:類似性を設定する
http://codeup.cn/problem.php?cid=100000597&pid=0
トピックによると、最初に重複排除後の2つのセットの共通部分Ncを計算し、次に2つの要素の和集合と重複排除Ntを計算し、2つを除算します。
例:
1 和 2 集合 交集有 87 101
并集有 99 87 101 5
2/4=0.5
1 和 3 集合 交集有 99 101
并集有 87 101 99 18 5 135
2/6=1/3
アイデアは、aとbの繰り返し数の数nを見つけて、
a.size()+ b.size()-n =結合の数
mn / mを使用することです。
#include<cstdio>
#include<set>
#include<iostream>
using namespace std;
set<int> s[200];
int main(void)
{
int n;
int m;
int i,j;
int number;
cin>>n;
j=0;
while(n)
{
cin>>m;
for(i=0;i<m;i++)
{
scanf("%d",&number);
s[j].insert(number);
}
n--;
j++;
}
int w,a,b;
set<int>::iterator it;
cin>>w;
while(w)
{
scanf("%d %d",&a,&b);
int temp;
int count=0;
for(it=s[a-1].begin();it!=s[a-1].end();it++)
{
if(s[b-1].find(*it)!=s[b-1].end())//说明重复了
{
count++;
}
}
int ans=s[b-1].size()+s[a-1].size()-count;
printf("%.1lf%%\n",100*(double)count/ans);
w--;
}
return 0;
}