1063. Set Similarity
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 M integers 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%
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
set<int> num[];
int main(){
int N, M, temp, K;
scanf("%d", &N);
for(int i = ; i <= N; i++){
scanf("%d", &M);
for(int j = ; j < M; j++){
scanf("%d", &temp);
num[i].insert(temp);
}
}
scanf("%d", &K);
int s1, s2;
for(int i = ; i < K; i++){
scanf("%d %d", &s1, &s2);
int same = , diff = num[s2].size();
for(set<int> ::iterator it = num[s1].begin(); it != num[s1].end(); it++){
if(num[s2].find(*it) != num[s2].end())
same++;
else diff++;
}
double rate = 1.0 * same / diff * 100.0;
printf("%.1lf%%\n", rate);
}
cin >> N;
return ;
}
总结:
1、set可以用于hash表解决不了的情况,比如键值不是int的情况。
2、printf输出%时,需要输出%%。
1063. Set Similarity的更多相关文章
- 1063. Set Similarity (25)
1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- 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 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- 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 (25) 待改进
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the ...
- PAT 甲级 1063 Set Similarity
https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 Given two sets of inte ...
- 1063 Set Similarity (25分)
Given two sets of integers, the similarity of the sets is defined to be /, where Nc is the number ...
- PAT 1063 Set Similarity (25)
题意:给你n个集合,k次询问,每次询问求两个集合的(交集)/(并集). 思路:k有2000,集合大小有10000.先将每个集合排序,对每个询问分别设两个指针指向两个集合的头.设a[i]为指针1的值,b ...
随机推荐
- mac下查看和设置环境变量
1.查看环境变量 命令 env 2.修改环境变量 命令 cd ~ && ls -a && sudo vim .bashrc 编辑输入要添加的环境变量 3.s ...
- RSA加密算法深入篇
如果你问我,哪一种算法最重要? 我可能会回答"公钥加密算法". 因为它是计算机通信安全的基石,保证了加密数据不会被破解.你可以想象一下,信用卡交易被破解的后果. 进入正题之前,我先 ...
- Dijkstra及其堆优化
朴素Dijkstra #include<bits/stdc++.h> using namespace std; const int inf=9999999; bool book[105]; ...
- Uniform Generator HDU1014
题意 给你公式seed(x+1) = [seed(x) + STEP] % MOD ,输入step和mod, 问你是否可以从第一项0,算到mod,它们是否都不同 是 good choice 否则 ba ...
- Beta版会议总结
开会时间:2015年06月12日 开会地点:基教601 开会人员:李想,王颖瑞,朱少辉,陈晨,侯涛亮. 开会内容:对于6月10日,大一同学的投票情况进行讨论和反思. 讨论结果如下: 一.目前存在的问题 ...
- “数学口袋精灵”App的第三个Sprint计划----开发日记
一.现状 上一阶段基本完成一个小游戏,游戏具有:随机产生算式,判断对错功能.通过轻快的背景音乐,音效,给玩家提供一个良好的氛围. 二.任务认领 完成界面,基本功能后的后续任务: 冯美欣:设计&qu ...
- Minor GC vs Major GC vs Full GC
http://www.importnew.com/15820.html https://plumbr.io/blog/garbage-collection/minor-gc-vs-major-gc-v ...
- Sqlite,libevent,openssl,mosquito交叉编译
一.设置交叉编译环境 在makefile所在目录(或源代码根目录)打开终端. 在终端中设置交叉编译所需的临时环境变量(也可写到配置文件中设置为全局环境变量),其中交叉编译工具链的名称和目录需要根据实际 ...
- 安装rlwrap 的简单方法
1. 下载安装 epel包 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 2. 安装r ...
- hive数据导入load导入命令
LOCAL 指的是操作系统的文件路径,否则默认为HDFS的文件路径 1.向t2和t3的数据表中导入数据 2.导入操作系统的一下三个文件 执行导入命令 3.将HDFS文件中的数据导入到t3中 4.导入 ...