PTA-集合相似度[通俗易懂]

PTA-集合相似度[通俗易懂]输入样例 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 define x first define y second define send string nops using namespace std typedef


输入样例:

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
#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 PII;
typedef struct Node * pnode;
set a[N];
vector 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::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;
setss;
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);
}

}
编程小号
上一篇 2025-02-20 21:33
下一篇 2025-03-03 12:30

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/131969.html