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. HDU 4460 Friend Chains

    Problem Description For a group of people, there is an idea that everyone is equals to or less than ...

  2. vim 配置文件——部分配置

    //vim 相关 set nu set showmatch set autoindent set smartindent set ruler set incsearch set tabstop=4 s ...

  3. [转]浅谈微信小程序

    本文转自:http://www.cnblogs.com/liziyou/p/6340159.html 微信小程序 1.什么是小程序 小程序是指微信公众号平台小程序,小程序可以在微信内被便捷的获取和转播 ...

  4. 数据库中存放着HTML并附带样式,如何在界面上对已有的样式进行修改

    在工作中遇到这样一个问题,数据库中存放着HTML代码,并且还带有样式,我要在界面上修改他已经写好的样式,例如把这个字段的字体改成微软雅黑,数据库中对应字段内容如下图 在界面面上是直接把上图这段HTML ...

  5. 【学习笔记】HTML基础:列表、表格与媒体元素

    一.列表是信息资源的一种展现形式,它可以使信息结构化和条理化,并以列表的样式显示出来,以便浏览者能够快速的获取相应的信息. 1.无需列表 <ul> <li>第一项</li ...

  6. mysql 语句学习一 关于系统信息的查询

    首先说一下,SQL语句是不区分大小写的. 1.SELECT VERSION();           -- 查询当前版本号 2.SELECT CURRENT_TIME(); -- 查询当前时间 3.S ...

  7. 菜鸟学习Spring——SpringMVC注解版解析不同格式的JSON串

    一.概述 不同格式的JSON串传到后台来实现功能这个是我们经常要做的一件事,本篇博客就给大家介绍四种不同的JSON串传到后台后台如何用@RequestBody解析这些不同格式的JSON串的. 二.代码 ...

  8. Hbase到Solr同步常用操作

    Hbase到Solr同步常用操作 1. 整体流程 2. 常用操作 Hbase常用操作 Solr常用操作 hbase-index常用操作 3. 其他资料 Lily HBase Indexer使用整理 h ...

  9. arcgis server 10.1 发布动态图层展示海量及频繁更新的数据步骤

    Arcgis server  发布动态图层及调用动态图层 做这个动态图层功能的原由是 有一个30万的数据需要通过arcgis GP工具转成shp然后渲染加载进地图,原来的做法是遍历生成shp面要素,读 ...

  10. Linux中怎么从root用户切换到普通用户

    su是在用户间切换,可以是从普通用户切换到root用户, test@ubuntu:~$ su Password:  root@ubuntu:/home/test# 也可以是从root用户切换到普通用户 ...