pta集合相似度_结构相似度

pta集合相似度_结构相似度原题链接输入样例:33 99 87 1014 87 101 5 877 99 101 18 5 135 18 9921 21 3输出样例:50.00%33.33%#include<bits/stdc++.h>#define x first#define y second#define send string::nopsusing namespace std;typedef long long ll;const int N = 1e4 + 10;cons

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

原题链接

在这里插入图片描述
输入样例:

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>
#define x first
#define y second
#define send string::nops
using namespace std;
typedef long long ll;
const int N = 1e4 + 10;
const int M = 3 * N;
const int INF = 0x3f3f3f3f;
typedef pair<int,int> PII;
typedef struct Node * pnode;
set<int> a[N];
vector<int> aa[N];
int main(){ 
   
    ios::sync_with_stdio(false);
    int n,k,x,y,m;
    cin>>n;
    for(int i = 1;i <= n;i ++){ 
   
        cin>>k;
        for(int j = 0;j < k;j ++){ 
   
            cin>>x;
            a[i].insert(x);
        }
        for(set<int>::iterator it = a[i].begin();it != a[i].end();it ++)aa[i].push_back(*it);
    }
    cin>>m;
    for(int i = 0;i < m;i ++){ 
   
        cin>>x>>y;
        set<int>ss;
        for(int j = 0;j < aa[x].size();j ++){ 
   
            if(a[y].find(aa[x][j]) != a[y].end()){ 
   
                ss.insert(aa[x][j]);
            }
        }
        int com = aa[x].size() + aa[y].size();
        printf("%.2f%%\n",ss.size() / double(com - ss.size())  * 100);
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/168948.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号