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. Unity游戏项目常见性能问题

    Unity技术支持团队经常会对有需求的客户公司项目进行游戏项目性能审查与优化,在我们碰到过的各种项目相关的问题中也有很多比较共同的方面,这里我们罗列了一些常见的问题并进行了归类,开发者朋友们可以参考下 ...

  2. 搭架Ubuntu的 apt-cacher服务

    源服务器名称可能不太准确,意思是创建内网自己的私服,这样只要有Ubuntu通过该私服下载安装过软件,私服都会缓存,下一个Ubuntu的请求就直接从缓存中获取. 最近Ubuntu源服务器太慢了,北京的网 ...

  3. [Scala] Currying

    Currying是一種函數式編程技巧, 指的是把接受多個參數的函數變換成接受一個單一參數的函數. 以一個簡單的例子在Scala中實現.. def f(a:Int, b:Int)={ a+b } //f ...

  4. docker 摘要(入门版)

    Docker 安装 macOS或者windows 下载boot2docker工具 CentOS yum install docker-io -y systemctl start docker dock ...

  5. nyoj 349&Poj 1094 Sorting It All Out——————【拓扑应用】

    Sorting It All Out 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 An ascending sorted sequence of distinct ...

  6. js字符操作

    js字符串方法预览: fromCharCode(num1, num2,,,), charAt(), charCodeAt(), length, split(''), slice(start, end? ...

  7. jquery监控input输入框的变化

    (function($) { $.fn.watch = function(callback) { return this.each(function() { //缓存以前的值 $.data(this, ...

  8. 归并排序——Java实现

    一.排序思想 将两个或两个以上的一排序文件合并成一个有序文件的过程叫归并,而归并排序就是建立在归并操作上的一种有效的排序算法,该算法是采用分治法的一个非常典型的应用.将以有序的了序列合并,得到完全有序 ...

  9. 引爆你的Javascript代码进化 (转)

    转自 海玉的博客 方才在程序里看到一段JS代码,写法极为高明,私心想着若是其按照规范来写,定可培养对这门语言的理解,对JS编程能力提高必是极好的.说人话:丫代码写的太乱,看的窝火! 最近闲暇无事,准备 ...

  10. IT集中监控

    监控的从底层到上应该是: 一 数据采集层 二 数据处理层 三 数据展示层 监控需要和ITIL中定义的服务进行相当多的交互,例如监控会使用配置管理数据库CMDB来记录和读取数据,会将事件处理方式从知识库 ...