1063 Set Similarity (25 分)

Given two sets of integers, the similarity of the sets is defined to be N​c​​/N​t​​×100%, where N​c​​ is the number of distinct common numbers shared by the two sets, and N​t​​ 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 (≤10​4​​) and followed by M integers in the range [0,10​9​​]. 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[比较]的更多相关文章

  1. PAT 1063. Set Similarity

    1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...

  2. PAT 1063 Set Similarity (25)

    题意:给你n个集合,k次询问,每次询问求两个集合的(交集)/(并集). 思路:k有2000,集合大小有10000.先将每个集合排序,对每个询问分别设两个指针指向两个集合的头.设a[i]为指针1的值,b ...

  3. 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 ...

  4. 1063 Set Similarity——PAT甲级

    1063 Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*10 ...

  5. 1063. Set Similarity (25)

    1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  6. 【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 ...

  7. PAT 甲级 1063 Set Similarity

    https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 Given two sets of inte ...

  8. PAT (Advanced Level) 1063. Set Similarity (25)

    读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...

  9. PAT甲题题解-1063. Set Similarity (25)-set的使用

    题意:两个整数集合,它们的相似度定义为:nc/nt*100%nc为两个集合都有的整数nt为两个集合一共有的整数注意这里的整数都是各不相同的,即重复的不考虑在内.给出n个整数集合,和k个询问,让你输出每 ...

随机推荐

  1. HIbernate與不支持boolean的數據庫之間的映射

    http://soft-development.iteye.com/blog/1225274 ————————————————————————————————————————————————————— ...

  2. Spring Boot简化了基于Spring的应用开发

    Spring Boot简化了基于Spring的应用开发,通过少量的代码就能创建一个独立的.产品级别的Spring应用. Spring Boot为Spring平台及第三方库提供开箱即用的设置,这样你就可 ...

  3. python爬虫<urlopen error [Errno 10061] >

    在网上看了十几篇文章,都是说的是IE的代理设置,具体是: Tools->Internet Options->Connections->Lan Settings 将代理服务器的小勾勾去 ...

  4. ThinkPHP项目笔记之登录,注册,安全退出篇

    1.先说注册 a.准备好注册页面,register.html,当然一般有,姓名,邮箱,地址等常用的. b."不要相信用户提交的一切数据",安全,安全是第一位的.所以要做判断,客户端 ...

  5. Run time setting设置详解

    Pacing转载自belie 1>     Run time setting设置中的Browser:‘Simulate a new user on each iteration’选项例如:录制了 ...

  6. mac下MAMP的安装和使用

    详情博客:https://my.oschina.net/laiconglin/blog/514139

  7. Python学习笔记4—列表List

    列表定义 Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. >>> a=['] >>> type(a) &l ...

  8. [SharePoint 2010]Sandboxed Solution (沙箱解決方案)

    現有的SharePoint 2007系統中,我們如果要安裝客製化的程式碼到系統中,我們必須製作一個解決方案包裝檔(Solution Package),然後在系統的中央管理後台中,真對整個伺服器農場Fa ...

  9. git--简单操作

    Git简介 一.      安装 下载地址: https://git-scm.com/downloads: https://pan.baidu.com/s/1kU5OCOB#list/path=%2F ...

  10. Spring WebSocket实现消息推送

    第一步: 添加Spring WebSocket的依赖jar包 (注:这里使用maven方式添加 手动添加的同学请自行下载相应jar包放到lib目录) <!-- 使用spring websocke ...