zoukankan      html  css  js  c++  java
  • L2-005 集合相似度 (25 分)

    L2-005 集合相似度 (25 分)

    给定两个整数集合,它们的相似度定义为:(frac{N_{c}}{N_{t}} imes 100 \%)。其中 (N_{c}) 是两个集合都有的不相等整数的个数,(N_{t}) 是两个集合一共有的不相等整数的个数。你的任务就是计算任意一对给定集合的相似度。

    输入格式:

    输入第一行给出一个正整数 (N ; (leq 50)),是集合的个数。随后 (N) 行,每行对应一个集合。每个集合首先给出一个正整数 (M ; (leq 10^{4})),是集合中元素的个数;然后跟 (M)([0,10^{9}]) 区间内的整数。
    之后一行给出一个正整数 (K ; (leq 2000)),随后 (K) 行,每行对应一对需要计算相似度的集合的编号(集合从 (1)(N) 编号)。数字间以空格分隔。

    输出格式:

    对每一对需要计算的集合,在一行中输出它们的相似度,为保留小数点后 (2) 位的百分比数字。

    输入样例:

    3
    3 99 87 101
    4 87 101 5 87
    7 99 101 18 5 135 18 99
    2
    1 2
    1 3
    

    输出样例:

    50.00%
    33.33%
    

    参考代码:

    #include<bits/stdc++.h>
    using namespace std;
    int n,k,x,q,a,b,c,t;
    set<int>s[55];
    int main()
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>k;
            while(k--)
            {
                cin>>x;
                s[i].insert(x);
            }
        }
        cin>>q;
        while(q--)
        {
            cin>>a>>b;
            c=0,t=s[b].size();
            for(auto it:s[a])
                if(s[b].find(it)==s[b].end())t++;
                else c++;
            cout<<fixed<<setprecision(2)<<c*100.0/t<<'%'<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    KM匹配模板
    BestCoder 1st Anniversary 1002-1005
    SGU 106 The equation
    sgu 104 Little shop of flowers
    SGU Magic Pairs
    关于 “'sqlite3' 不是内部或外部命令.....”问题
    通过django 速成 blog
    windows 通过appache链接cgi程序
    A Lot of Games(Trie树 + 博弈)
    树的点分治 (poj 1741, 1655(树形dp))
  • 原文地址:https://www.cnblogs.com/LengYun/p/14691079.html
Copyright © 2011-2022 走看看