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个询问,让你输出每 ...
随机推荐
- CI 如何获取get请求过来的数据
http://localhost/ci_tuangou/index.php/home/index/index?gid=2 echo 'gid='. $this->input->get('g ...
- 002Maven_第一个Maven演示
第一步. 首先建立Hello项目同时建立Maven约定的目录结构 Hello --src -----main ----------java ----------reso ...
- ConfigParser 读写配置文件
一.ini: 1..ini 文件是Initialization File的缩写,即初始化文件,是windows的系统配置文件所采用的存储格式 2.ini文件创建方法: (1)先建立一个记事本文件.(2 ...
- 介绍MFC框架中涉及到的设计模式(二)
接着上一篇<介绍MFC框架中涉及到的设计模式(一)>介绍 单例模式(Singleton Pattern) 单例模式是一种经常使用的软件设计模式.在它的核心结构中仅仅包括一个被称为单例类的特 ...
- jQuery插件手把手教会(一)
jQuery插件开发教程 ——让你的jQuery水平提升一个台阶 要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台 ...
- Android下在onCreate中获取控件的宽度和高度(通过回调)
有时候需要在onCreate方法中知道某个View组件的宽度和高度等信息, 而直接调用View组件的getWidth().getHeight().getMeasuredWidth().getMeasu ...
- webpack 报错 path is not defind
webpack.config.js里的内容是这样的,注意标红的地方: 首先,绝对路径'./dist'是 没有问题的 那么,查了很多,最后看到别人的webpack.config.js里面这样写着,现在c ...
- jquery如何获取type=hidden的input元素的值?
function setHiddenFields() { var hiddens = $("input:hidden"); $.each(hiddens, function (in ...
- Linux下查看nginx的安装路径
输入:nginx -V 输出:configure arguments: --prefix=/usr/local/nginx
- nexus配置第三方库文件
进入nexus管理界面 默认用户名密码:admin/admin123 在左侧Views/Repositories中选择Repositories,然后在右侧的面板中选择3rd party,在下方arti ...