1063. Set Similarity

题目大意

给定 n 个集合, k 个询问, 求任意两个集合的并集和合集.

思路

一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 vector勉强过了, 最后才发现原来如此简单.

代码

#include <cstdio>
#include <set>
#include <vector>
using namespace std;
int main(){
int nSet;
scanf("%d", &nSet);
vector<set<int> > sts(nSet + 1);
for(int i = 1; i <= nSet; i++){
int nNum;
scanf("%d", &nNum);
set<int> temp;
for(int j = 0; j < nNum; j++){
int val;
scanf("%d", &val);
temp.insert(val);
}
sts[i] = temp;
}
int nQuery;
scanf("%d", &nQuery);
for(int i = 0; i < nQuery; i++){
int a, b;
scanf("%d %d", &a, &b);
int Nc = 0;
int Nt = sts[a].size() + sts[b].size();
for(set<int>::iterator ita = sts[a].begin(); ita != sts[a].end(); ++ita){
if(sts[b].find(*ita) != sts[b].end()){
Nc++; Nt--;
}
}
printf("%.1f%%\n", Nc * 100.0 / Nt);
}
return 0;
}

PAT 1063. Set Similarity的更多相关文章

  1. PAT 1063 Set Similarity[比较]

    1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...

  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. Root用户让其他用户运行某程序

    这里以启动tomcat为例 1.安装tomcat不介绍了,自己百度 2.测试能否使用,略 3.创建tomcat用户 useradd tomcat -s /sbin/nologin 创建tomcat,禁 ...

  2. 【Xshell】设置XShell最大的显示行数

    选择会话,依次点击“文件"->"属性”,打开“会话属性”窗体   在“会话属性”窗体中,选择“终端”,下图中红框标注的地方是“缓冲区大小”,修改其中的值,其范围在0~2,14 ...

  3. Unity3D第一课之自转与公转

    1.物体公转,即围绕一个中心物体旋转 public class gongzhuan : MonoBehaviour { public GameObject Axis;//轴,用于选择围绕中心 publ ...

  4. DJango小总结一

    views.py                        def func(request):                # 包含所有的请求数据                ...     ...

  5. 获取当前的日期时间的js函数,格式为“yyyy-MM-dd hh:mm:ss”

    //获取当前的日期时间函数,格式为“yyyy-MM-dd hh:mm:ss” function getNowFormatDate(date) { if (date == null) { var dat ...

  6. oracle学习篇十二:索引

    索引: 查询User_indexes可以获取有关用户已创建的索引的详细信息. 查询User_ind_partitions可以获取有关用户已创建的分区索引的详细信息. 查询User_ind_column ...

  7. SharePoint Designer - View

    1. 数据视图 可以将图片.新闻等列表(如: Announcement)用以下视图显示,具体做法可以参考这篇文章,但需要强调几个地方: 1.1 选择了视图样式后,需要点击“自定义” --> &q ...

  8. 关于ButterKnife 设置全局配置

    先在项目的根目录的build.grade添加:classpath'com.neenbedankt.gradle.plugins:android-apt:1.8'  然后在app build.grade ...

  9. Eclipse 各版本名称的由来

    2001年11月7日 ,Eclipse 1.0发布 半年之后,2002年6月27日Eclipse进入了2.0时代.2.0时代的Eclipse经历了2.0和2.1两个大的版本.其中2.0在 之后又推出了 ...

  10. java面试题之----数据库事务的四大特性及隔离级别

    本篇讲诉数据库中事务的四大特性(ACID),并且将会详细地说明事务的隔离级别. 如果一个数据库声称支持事务的操作,那么该数据库必须要具备以下四个特性: ⑴ 原子性(Atomicity) 原子性是指事务 ...