天梯赛

题目链接:https://www.patest.cn/contests/gplt/L2-005

这个题理解是个大问题啊,“给定两个整数集合,它们的相似度定义为:Nc/Nt*100%。其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数。你的任务就是计算任意一对给定集合的相似度。”  理解了很久,用set来去重。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <set>
 6 using namespace std;
 7 const int maxn = 55;
 8 set<int> gather[maxn];
 9 int main()
10 {
11     int n = 0,m = 0;
12     scanf("%d",&n);
13     for(int i=1;i<=n;i++)
14     {
15         scanf("%d",&m);
16         for(int j=0;j<m;j++)
17         {
18             int x;
19             scanf("%d",&x);
20             gather[i].insert(x);
21         }
22     }
23     int k = 0;
24     scanf("%d",&k);
25     int l = 0,r = 0;
26     while(k--)
27     {
28         scanf("%d %d",&l,&r);
29         int Count = 0;
30         set<int>::iterator it;
31         for(it=gather[l].begin();it!=gather[l].end();it++)
32         {
33             if(gather[r].count(*(it)))
34             {
35                 Count++;
36             }
37            // printf("%d
",*it);
38         }
39         printf("%.2f%%
",(double)Count/(double)(gather[l].size()+gather[r].size()-Count)*100.0);
40     }
41     return 0;
42 }
原文地址:https://www.cnblogs.com/littlepear/p/6528561.html