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个询问,让你输出每 ...
随机推荐
- selenium:chromedriver与chrome版本的对应关系
转自:http://blog.csdn.NET/huilan_same/article/details/51896672 再使用selenium打开chrome浏览器的时候,需要用chromedriv ...
- iOS开发 - CALayer图层
CALayer的基本使用 在iOS中.你能看得见摸得着的东西基本上都是UIView.比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView 事实上UIView之所以能显 ...
- C++之函数模板
C++之函数模板与模版函数 直接上代码: C++ Code 12345678910111213141516171819202122232425262728293031323334353637383 ...
- MFC WinInetHttp抓取网页代码内容
Windows Internet编程主要包括两方面: l 服务器端 l 客户端 WinInet编程 Internet客户端主要实现的功能,主要是通过Internet协议(HTTP.FTP等)获 ...
- nat123动态域名解析软件使用教程
nat123动态域名解析软件使用教程
- 电力项目十四--js添加highslider特效
当页面的一个table表格无法显示所有的内容的时候,点击[查看详细信息],显示详细内容: 下载css,js 1.在actingIndex.jsp中添加:引入js和css: <LINK href= ...
- mysql数据的导入与导出
参考:http://blog.sina.com.cn/s/blog_81b2b2a1010188q0.html http://blog.csdn.net/xin_yu_xin/article/det ...
- LeetCode 笔记系列16.2 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]
题目:Given a string S and a string T, find the minimum window in S which will contain all the characte ...
- 160429、nodejs--Socket.IO即时通讯
动态web 在html5以前,web的设计上并没有考虑过动态,他一直是围绕着文档设计的,我们看以前比较老的网站,基本上都是某一刻用来显示单一的文档的,用户请求一次web页面,获取一个页面,但是随着时间 ...
- ubuntu squid 代理服务器安装配置
安装: 下载安装包 http://pan.baidu.com/s/1mitvwpE 解压 tar -xzvf file.tar.gz 编译: 进入sbin目录 执行 ./configure --pr ...