PAT 甲级 1063 Set Similarity
https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928
Given two sets of integers, the similarity of the sets is defined to be /, 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 (≤) which is the total number of sets. Then N lines follow, each gives a set with a positive M (≤) and followed by M integers in the range [0]. After the input of sets, a positive integer K (≤) 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%
代码:
#include <bits/stdc++.h>
using namespace std; int N, M; int main() {
scanf("%d", &N);
set<int> s[N + 1];
for(int i = 1; i <= N; i ++) {
int x;
scanf("%d", &x);
for(int j = 0; j < x; j ++) {
int y;
scanf("%d", &y);
s[i].insert(y);
}
} scanf("%d", &M);
while(M --) {
int a, b;
scanf("%d%d", &a, &b);
int num = 0;
for(set<int>::iterator it = s[b].begin(); it != s[b].end(); it ++)
if(s[a].find(*(it)) != s[a].end())
num ++; printf("%.1f%%\n", (double)num / (s[a].size() + s[b].size() - num) * 100);
}
return 0;
}
前两天第一次交居然 0 !!!!! 今天才发现输出一位我输出两位。。。。 不用 set 会超时
后天出去玩 今天已经不是很想写了 哭唧唧
PAT 甲级 1063 Set Similarity的更多相关文章
- PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- 【PAT】1063. Set Similarity (25) 待改进
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the ...
- PAT甲级——A1063 Set Similarity
Given two sets of integers, the similarity of the sets is defined to be /, where Nc is the number ...
- pat(A) 1063. Set Similarity(STL)
代码: #include<cstdio> #include<cstring> #include<set> using namespace std; set<i ...
- 1063 Set Similarity——PAT甲级
1063 Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*10 ...
- PAT 1063 Set Similarity[比较]
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...
- PAT 1063. Set Similarity
1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 【转载】【PAT】PAT甲级题型分类整理
最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...
随机推荐
- 《浅析Entity Framework Core中的并发处理》引起的思考
看到一篇关于EF并发处理的文章,http://www.cnblogs.com/GuZhenYin/p/7761352.html,突然觉得为什么常见业务中为什么很少做并发方面的考虑.结合过去的项目,这样 ...
- 20155301 《Java程序设计》实验五网络编程与安全
20155301 <Java程序设计>实验五网络编程与安全 实验内容 实验1: 两人一组结对编程:参考http://www.cnblogs.com/rocedu/p/6766748.htm ...
- 2016-2017-2 20155339《 java面向对象程序设计》实验四Android程序设计
2016-2017-2 20155339< java面向对象程序设计>实验四Android程序设计 实验内容 1.Android Stuidio的安装测试: 参考<Java和Andr ...
- MySQL 安装 + Windows7
Window版本 1.下载 http://dev.mysql.com/downloads/mysql/ 2.解压 如果想要让MySQL安装在指定目录,那么就将解压后的文件夹移动到指定目录,如:D:\m ...
- 【LG5055】可持久化文艺平衡树
[LG5055]可持久化文艺平衡树 题面 洛谷 题解 终于不可以用\(Trie\)水了... 和普通的\(FHQ\;treap\)差不多 注意一下\(pushdown\).\(split\)要新开节点 ...
- 带偏移量的AES加密工具
自定义的一个对称加密工具类AESUtil.java public static final String ENCRYPTION_ALGORITHM = "AES"; public ...
- charles录制https请求
之前一直用windows系统,抓包什么的都是用的fiddler或者wireshark,操作比较简单,扩展性也比较强,现在因为工作原因换了mac,在网上一直没有找到fiddler的mac版本,就只能切换 ...
- python根据正则表达式的简单爬虫
今天根据正则表达式简单的爬了一下大众点评,把北京的美食爬了爬,(店铺名,人均消费,地址) import re import urllib.request from urllib.request imp ...
- Selenium2+python自动化-文件上传
前言 文件上传是web页面上很常见的一个功能,自动化成功中操作起来却不是那么简单. 一般分两个场景:一种是input标签,这种可以用selenium提供的send_keys()方法轻松解决:另外一种非 ...
- 445. Cosine Similarity【LintCode java】
Description Cosine similarity is a measure of similarity between two vectors of an inner product spa ...