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. JS常用的设计模式(6)——桥接模式

    桥接模式的作用在于将实现部分和抽象部分分离开来, 以便两者可以独立的变化.在实现api的时候, 桥接模式特别有用.比如最开始的singleton的例子. var singleton = functio ...

  2. UiPath进阶

    最近RPA比较火,UiPath工具排名前几位并且免费试用,很多朋友们都选择了学习自动化工具UiPath,今天我就向大家介绍一下UiPath的学习过程,希望对后来的学习这个工具的人有所帮助. UiPat ...

  3. 使用waitfor 语句

    aitfor语句用于延迟后面语句的执行,可以指定延迟时间长度是具体的时间.参考下面的语句: waitfor delay ’00:01:15’ print N’到时间了’    --也可以不加N 字符串 ...

  4. 项目搭建系列之二:SpringMVC框架下配置MyBatis

    1.什么是MyBatis? MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis ...

  5. 2017年10月30日 vs初级教学

    Console.Write("Hello World!"); / / 插入 Hello World!            Console.WriteLine("Hell ...

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

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

  7. Android-自定义View实现ImageView播放gif

    http://blog.csdn.net/guolin_blog/article/details/11100315 总体思路是这样的 PowerImageView类继承ImageView类 给Powe ...

  8. SQL使用bcp方式导入,导出数据2

    select * from A_Account   EXEC sp_configure 'allow_updates' GO EXEC sp_configure 'allow_updates',0; ...

  9. oracle学习篇十一:视图

    视图是存储的查询定义. 1. 创建视图的语法如下: Create [OR REPLACE] [FORCE | NOFORCE] VIEW view_name[(alias,alias,...)] AS ...

  10. vue——计算属性和侦听器

    一.计算属性(data中的相关数据) 侦听多个属性时——计算属性 comuted. 模板内的表达式非常便利,但是设计它们的初衷是用于简单运算的.在模板中放入太多的逻辑会让模板过重且难以维护.例如: & ...