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 ...
随机推荐
- 对于ps基本操作的归纳
1.开始新的制作 1)新建 快捷键:Ctrl+n 格式:宽高根据要求自选:颜色模式常用R(红)G(绿)B(蓝) 2)打开电脑上的图片 快捷键:Ctrl+o 2.选框工具 快捷键:M 作用:能 ...
- AnyProxy做App网络流量测试
前言: AnyProxy是一个开放式的HTTP代理服务器.Github主页:[https://github.com/alibaba/anyproxy]主要特性包括: 基于Node.js,开放二次开发能 ...
- android studio报Resolved versions for app (26.1.0) and test app (27.1.1)differ. 错误的解决办法
https://blog.csdn.net/qq_36636969/article/details/80278150
- STL next_permutation()
用法 字典序全排列 可以发现函数next_permutation()是按照字典序产生排列的,并且是从数组中当前的字典序开始依次增大直至到最大字典序. 代码 #include<iostream&g ...
- Beta版本发布报告
项目名称 学霸系统写手机客户端 项目版本 Beta版本 负责人 北京航空航天大学计算机学院 hots团队 联系方式 http://www.cnblogs.com/hotsbuaa/ 要求发布日期 20 ...
- github链接地址及
http://www.github.com/houyanan1/test.git git 在本地创建分支,并且已经在该分支中开发了一段时间,那么commit到本地后,代码会做一个提交快照,在本地分支保 ...
- 四则运算安卓版ver.mk3
在原有的基础上做了些许改动以及添加了一点小功能,以下是代码: package com.example.add; import java.io.File; import com.example.add. ...
- Sonatype Nexus 2.11.1-01 使用入门
nexus安装与启动 linux下: 安装路径 /home/maven/nexus-2.11.1-01/ 启动方法 ./bin/nexus start windows下: 管理员模式运行cmd.exe ...
- vue的自定义组件和组件传值
<div id="app"> <div>{{pmessage}}</div> //父组件 <child :message="pm ...
- Event事件2
1,阻止默认行为: 2,事件监听 3,事件流之事件捕获 4,事件委托 阻止默认行为 浏览器中有很多默认行为,比如当点击a标签后,会发生链接的跳转.当点击鼠标的右键时, 会显示右键菜单等. 有些时候,浏 ...