2020.11.14天梯赛练习*6 补题

7-11 集合相似度 (25分)

 

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 1100;

int n, m;

set<int> st[N];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1;i <= n; ++ i){
        scanf("%d", &m);
        for(int j = 0;j < m; ++ j){
            int x;
            scanf("%d", &x);
            st[i].insert(x);
        }
    }
    scanf("%d", &m);
    while(m --){
        int x, y;
        scanf("%d %d", &x, &y);
        set<int>::iterator it1 = st[x].begin();
        set<int>::iterator it2 = st[y].begin();
        int cnt = 0;
        while(it1 != st[x].end() && it2 != st[y].end()){
            if(*it1 == *it2) cnt ++, it1 ++, it2 ++;
            else if(*it1 > *it2) it2 ++;
            else it1 ++; 
        }
        printf("%.2lf%%\n", 1.0 * cnt / (st[x].size() + st[y].size() - cnt) * 100.0);
    }
}

 

posted @ 2020-11-22 22:13  IIlIlIlI  阅读(53)  评论(0编辑  收藏  举报