zoukankan      html  css  js  c++  java
  • PAT 天梯赛 L2-005. 集合相似度 【SET】

    题目链接

    https://www.patest.cn/contests/gplt/L2-005

    思路
    因为集合中的元素 是不重复的 所以用SET 来保存 集合
    然后最后 查找一下 两个集合中共有元素 就可以了

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    
    const double PI  = 3.14159265358979323846264338327;
    const double E   = 2.718281828459;
    const double eps = 1e-6;
    
    const int INF    = 0x3f3f3f3f;
    const int maxn   = 1e5 + 5;
    const int MOD    = 1e9 + 7;
    
    int main()
    {
        set <int> s[51];
        int n, num, k;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &k);
            for (int j = 0; j < k; j++)
            {
                scanf("%d", &num);
                s[i].insert(num);
            }
        }
        scanf("%d", &k);
        int x, y;
        for (int i = 0; i < k; i++)
        {
            scanf("%d%d", &x, &y);
            int nt = s[x].size() + s[y].size();
            int nc = 0;
            set <int>::iterator it;
            for (it = s[x].begin(); it != s[x].end(); it++)
            {
                if (s[y].count(*it))
                    nc++;
            }
            nt -= nc;
            printf("%.2lf%%
    ", nc * 1.0 / nt * 100);
        }
    }
  • 相关阅读:
    mysql 练习
    linux 常用软件安装-目录
    Python 三大神器
    Mysql 数据库安装配置
    Mysql数据库入门
    maven的安装与基本使用
    分布式事务
    分布式锁
    springcloud学习笔记
    springboot入门使用
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433258.html
Copyright © 2011-2022 走看看