1063 Set Similarity (PAT甲级)

news/2024/11/26 4:52:55/

大半个月没做题,手非常生...

#include <cstdio>
#include <vector>
#include <map>int N, M, K, t, m, n;
std::vector<std::map<int, int>> vec;void similarity(int a, int b){int cnt = 0;for(auto c : vec[a]){if(vec[b].find(c.first) != vec[b].end()){++cnt;}}printf("%.1f%%\n", cnt * 100.0 / (vec[a].size() + vec[b].size() - cnt));
}int main(){scanf("%d", &N);vec.resize(N + 1);for(int i = 1; i <= N; ++i){scanf("%d", &M);for(int j = 0; j < M; ++j){scanf("%d", &t);vec[i][t] = 1;}}scanf("%d", &K);for(int i = 0; i < K; ++i){scanf("%d %d", &m, &n);similarity(m, n);}return 0;
}

题目如下:

Given two sets of integers, the similarity of the sets is defined to be Nc​/Nt​×100%, where Nc​ is the number of distinct common numbers shared by the two sets, and Nt​ is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.

Input Specification:

Each input file contains one test case. Each case first gives a positive integer N (≤50) which is the total number of sets. Then N lines follow, each gives a set with a positive M (≤104) and followed by Mintegers in the range [0,109]. After the input of sets, a positive integer K (≤2000) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.

Output Specification:

For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.

Sample Input:

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

Sample Output:

50.0%
33.3%

http://www.ppmy.cn/news/908949.html

相关文章

❤️创意网页:如何用HTML制作菜单栏?制作好看的菜单栏样式网页

✨博主&#xff1a;命运之光 &#x1f338;专栏&#xff1a;Python星辰秘典 &#x1f433;专栏&#xff1a;web开发&#xff08;简单好用又好看&#xff09; ❤️专栏&#xff1a;Java经典程序设计 ☀️博主的其他文章&#xff1a;点击进入博主的主页 前言&#xff1a;欢迎踏入…

CSAPP Lab入门探索

此为记录 虚拟机准备工作 下载VMware 直接在浏览器中搜索VMware Workstation即可 等待 安装就是直接下一步下一步即可&#xff0c;那个安装路径也改下&#xff0c;默认是装在系统盘中 许可证: 直接在百度中搜索VMware Workstation 17 Pro密钥大全即可 这里给出一个参考的&…

ping -f

ping -f 指定 flood-ping 选项。 -f 标志“倾倒”或输出信息包&#xff0c;在它们回来时或每秒 100 次&#xff0c;选择较快一个。 每一次发送 ECHO_REQUEST&#xff0c;都显示一个句号&#xff0c;而每接收到一个 ECHO_REPLY 信号&#xff0c;就显示一个退格。 这就提供了一…

FLN

最近看了一些模糊神经网络。 模糊系统的核心其实就是一个方程 IF antecedent, THEN consequent. 就是所谓的Rule-based System。最开始提出模糊系统是为了模拟人的reasoning过程&#xff0c;并且由于定义了Rule&#xff0c;就可以结合领域内的专家知识。antecedent可以有很多…

fhog

第一次看见fhog在研究复现KCF代码时 传统hog特征提取 hog特征&#xff08;梯度统计直方图&#xff09;--------1&#xff0c;对原图进行灰度化&#xff08;hog统计的是梯度信息&#xff0c;色彩几乎没有贡献&#xff09;。2再进行gamma压缩和归一化&#xff08;减轻光照影响&…

NFV介绍

转发自&#xff1a;https://zhuanlan.zhihu.com/p/26259440 NFV全称是Network Function Virtualization。这又是一个与网络相关的故事。先来看看NFV的前世今生吧。在NFV之前&#xff0c;NF&#xff08;NetworkFunction&#xff09;是一直存在的&#xff0c;网络中&#xff0c;…

nflog学习

nflog 是一种类似client/server的架构&#xff0c;需要进行nflog通信时&#xff0c;需要先启server。然后客户端才能发送数据给server。 server的工作 创建nfulnl_instance实体 nfulnl_recv_config--NFULNL_CFG_CMD_BIND--》instance_create 主要关注group号&#xff0c;这…