zoukankan      html  css  js  c++  java
  • CCCC L2-005. 集合相似度

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

    题解:直接set的count函数

    坑 :要用容斥原理算两个集合的并,否则超时。(我还以为要打表呢)

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <map>
    #include<stack>
    #include<set>
    #include<string.h>
    #include<list>
    #define pb push_back
    #define mp make_pair
    #define _for(i, a, b) for (int i = (a); i<(b); ++i)
    #define _rep(i, a, b) for (int i = (a); i <= (b); ++i)

    using namespace std;
    const int N = 50 + 5;

    set<int> s[N];

    int main() {
    int n;
    cin >> n;
    _for(i, 1, n+1) {
    int k;
    cin >> k;
    _for(j, 0, k) {
    int x;
    cin >> x;
    s[i].insert(x);
    }
    }
    int q;
    /*_for(i,1,n)
    _for(j, i+1, n + 1) {
    for (auto t : s[i]) if (s[j].count(i)) tc[i][j]++;
    tt[i][j] = s[i].size() + s[j].size() - 2*tc[i][j];
    }*///写了一半感觉容斥定理可能能ac
    cin >> q;
    _for(i, 0, q) {//2000*4000 8e6 tle;
    int x, y;
    cin >> x >> y;
    float nc=0, nt=0;
    set<int> t;
    for (auto t1 : s[x]) { if (s[y].count(t1)) nc++; }
    //for (auto t2 : s[y]) {t.insert(t2);}
    nt = s[x].size()+s[y].size()-nc;
    printf("%.2lf%% ", nc / nt * 100);
    }
    system("pause");
    }

    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    Python_异常处理
    Python_文件相关操作
    Python_集合
    Python_字典
    Python_元组
    Python_列表操作2
    Python_列表操作1
    Spring-Data-Jpa使用总结
    SpringBoot源码分析之---SpringBoot项目启动类SpringApplication浅析
    RESTful API批量操作的实现
  • 原文地址:https://www.cnblogs.com/SuuT/p/8669530.html
Copyright © 2011-2022 走看看