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 ...
随机推荐
- JAVA核心:内存、比较和Final
1.java是如何管理内存的 java的内存管理就是对象的分配和释放问题.(其中包括两部分) 分配:内存的分配是由程序完成的,程序员需要通过关键字new为每个对象申请内存空间(基本类型除外),所有的对 ...
- <<梦断代码>>阅读笔记二
这是第二篇读书笔记,这本书我已经读了有一大半了,感觉书中所描述的人都是疯子,一群有创造力,却又耐得住寂寞的疯子. 我从书中发现几点我比较感兴趣的内容. 第一个,乐高之梦.将程序用乐高积木一样拼接起来. ...
- Genymotion安装总结
周末的时候为了测试论文中的Almond虚拟助手软件,所以要去Google Play上去下载. 但是我的两个安卓模拟器:夜神和海马玩模拟器的安卓版本太低了,导致无法使用 谷歌服务,所以连商店都进不去. ...
- 通过JDOM实现XML与String的相互转换
利用JDOM实现XML与String之间的相互转换: package com.util.xml; import java.io.ByteArrayOutputStream; import java.i ...
- BUG管理工具——Mantis安装配置
配置环境: CentOS6.5(所有操作在root用户下面操作) 1. 关闭防火墙, service iptables stop(防止防火墙捣乱,或者还得手动添加端口号的麻烦) 2. Disable ...
- let申明与const申明
ES6新增了let命令,用来声明变时量. 它的用法类似于var 但是所声明的变量,只在let命令所在的代码块内有效. // for(let i = 0; i<10 ;i++ ){ console ...
- ECSHOP广告调用广告位添加到首页顶部通栏教程
ECSHOP广告调用广告位添加到首页顶部通栏教程 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2012-05-26 ECSHOP系统默认预留的广告位很少,如何才能 ...
- add (db.collection.add)添加数据
db.collection('cheshi').add({ data: { cheshi:4, } }).then((res) => { console.log(res) })
- CSS 选择器的兼容性
参考网站 http://blog.csdn.net/yume_sola/article/details/70215695 http://www.youdiancms.com/jianrong/614. ...
- charles代理以及关于其抓取https信息的操作
一直没有写一篇关于charles的文章来记录,但是发现偶尔还是会忘记,所以还是记一下,查起来比较方便. 首先在安装了charles之后默认的本地代理地址是 127.0.0.1:8888这个地址.如果希 ...