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个询问,让你输出每 ...
随机推荐
- Android Studio 工具栏添加图标
本文中 Android Studio 的版本为 Android Studio 2.2 ,操作系统为 Windows,如有操作不同,可能是版本差异.在工具栏中添加一些常用的图标有利于我们开发,举例说明: ...
- 【BZOJ】1679: [Usaco2005 Jan]Moo Volume 牛的呼声(数学)
http://www.lydsy.com/JudgeOnline/problem.php?id=1679 水题没啥好说的..自己用笔画画就懂了 将点排序,然后每一次的点到后边点的声音距离和==(n-i ...
- 【BZOJ】1696: [Usaco2007 Feb]Building A New Barn新牛舍(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1696 原题要求min(sum{|x-xi|+|y-yi|}),且一定要看题:“没有两头牛的吃草位置是 ...
- yii2.0操作数据库
首先不得不说yii2.0面向对象的比较彻底,建议没学过或者没学好面向对象的同学再看看面向对象. 其次切入正题. 先创建数据库,这步自己写. DROP TABLE IF EXISTS `country` ...
- bootstrap基础学习七篇
bootstrap图片 Bootstrap 提供了三个可对图片应用简单样式的 class: .img-rounded:添加 border-radius:6px 来获得图片圆角. .img-circle ...
- 浅谈AutoResetEvent的用法
using System;using System.Threading; namespace AutoResetEvent_Examples{ class MyMainClass { ...
- C语言二维数组
上节讲解的数组可以看作是一行连续的数据,只有一个下标,称为一维数组.在实际问题中有很多数据是二维的或多维的,因此C语言允许构造多维数组.多维数组元素有多个下标,以确定它在数组中的位置.本节只介绍二维数 ...
- Firefox 新增容器标签:可同时登录多个用户
Mozilla昨天在Firefox夜间构建版50.0a1中增加了一个名为“容器标签Container Tabs”的实验性功能. Mozilla的工程师称,该功能可以将用户的浏览会话分到不同的容器中.这 ...
- 1853: [Scoi2010]幸运数字[容斥原理]
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2405 Solved: 887[Submit][Status] ...
- 【BZOJ3831】[Poi2014]Little Bird 单调队列
[BZOJ3831][Poi2014]Little Bird Description In the Byteotian Line Forest there are trees in a row. ...