PAT 1063 Set Similarity[比较]
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 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%
题目大意:给出N个集合,并且给出查询,Nc表示两个集合中互异的相同的数的个数,Nt表示两个集合中不同的数的总数。求出二者的比例。
//我一看,这数据量太大了吧,不能蛮干,复杂度太高了。肯定是使用集合,但是怎么使用呢?我心里没有底。毕竟复杂度太高了。

//看了柳神的代码才恍然大悟,我是笨死了。
2018-11-18更————
又做了一遍AC了:
#include <iostream>
#include <set>
#include <cstdio>
using namespace std; set<int> st[];
int main() {
int n,m,t;
cin>>n;
for(int i=;i<n;i++){
cin>>m;
for(int j=;j<m;j++){
cin>>t;
st[i+].insert(t);
}
}
cin>>m;
int s1,s2;
for(int i=;i<m;i++){
cin>>s1>>s2;
int nc=,nt=;
//cout<<st[s1].size()<<" "<<st[s2].size()<<'\n';
for(auto it=st[s1].begin();it!=st[s1].end();it++){
// if(st[s2].find(*it)!=0){
// nc++;
// }
if(st[s2].find(*it)!=st[s2].end()){
nc++;
}
}
// set<int> s;
// s.insert(st[s1]);
// s.insert(st[s2]);
// nt=s.size();
nt=st[s1].size()+st[s2].size()-nc;
printf("%.1f%\n",1.0*nc/nt*);
} return ;
}
1.其中在写set的find函数时,一直不行,不能判==0或者1,而是set.end()才对。学习了。
PAT 1063 Set Similarity[比较]的更多相关文章
- PAT 1063. Set Similarity
1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...
- PAT 1063 Set Similarity (25)
题意:给你n个集合,k次询问,每次询问求两个集合的(交集)/(并集). 思路:k有2000,集合大小有10000.先将每个集合排序,对每个询问分别设两个指针指向两个集合的头.设a[i]为指针1的值,b ...
- 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 ...
- 1063. Set Similarity (25)
1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- 【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 ...
- PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT甲题题解-1063. Set Similarity (25)-set的使用
题意:两个整数集合,它们的相似度定义为:nc/nt*100%nc为两个集合都有的整数nt为两个集合一共有的整数注意这里的整数都是各不相同的,即重复的不考虑在内.给出n个整数集合,和k个询问,让你输出每 ...
随机推荐
- 【BZOJ】1646: [Usaco2007 Open]Catch That Cow 抓住那只牛(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1646 这一题开始想到的是dfs啊,,但是本机测样例都已经re了... 那么考虑bfs...很巧妙? ...
- 整理:java定时器。
本文纯属个人思路,如有错误,请指正. java的Timer依赖Thread,每一个Timer实际上都是一个Thread. import java.util.TimerTask; /** * 本类仅为实 ...
- 【NLP+Deep learning】好文
http://blog.jobbole.com/77709/ 原文出处: http://colah.github.io/posts/2014-07-NLP-RNNs-Representations/
- 数据降维PCA——学习笔记
PCA主成分分析 无监督学习 使方差(数据离散量)最大,更易于分类. 可以对隐私数据PCA,数据加密. 基变换 投影->内积 基变换 正交的基,两个向量垂直(内积为0,线性无关) 先将基化成各维 ...
- iOS开发之-- 从当前隐藏导航界面push到下一个显示导航界面出现闪一下的问题
在修改项目代码的过程中,遇到一个问题,就是比如主页面的导航栏是隐藏的,但是需要push到别的页面,这个时候,会出现导航栏闪一下的情况, 下面是我写的一种方案,也就是在loadView这个生命周期函数中 ...
- hdu1244(dp)
简单dp Max Sum Plus Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- [SharePoint 2010] SharePoint 2010上多人同時編輯Office 2010文件
Office 2010這個版本,提供了一個令人興奮的新功能,那就是它可以讓多人同時編輯一份Office 2010的文件. 這是一個很大的突破. 以往在與SharePoint搭配下的分享環境,檔案只能被 ...
- Android开源项目分类汇总【畜生级别】
From :http://blog.csdn.net/forlong401/article/details/25459403?c=6c4cd677a617db4655988e41ee081691#t7 ...
- [LeetCode] Maximum Subarray Sum
Dynamic Programming There is a nice introduction to the DP algorithm in this Wikipedia article. The ...
- DOS和BAT批量提取修改文件名
DOS命令窗口:开始-cmd-回车,进入DOS命令窗口 案例一.获取文件名 dir 1.输入"文件所在盘",回车,如: d: 2.输入"cd 文件夹位置",回车 ...