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. 一键压测工具改造(locust)

    本文内容来自“天外归云”大神,原文链接http://www.cnblogs.com/LanTianYou/p/5987741.html,目前只对启动脚本做了一些改造,应该说是,不适用powershel ...

  2. LaTex 2

    LaTex 入门 此时是否安装成功 如果安装成功了LaTeX, 那么在计算机上会多出来LaTeX的编译器, LaTex Live 安装包在计算机上安装了多个不同的编译器, 有latex, xelate ...

  3. bzoj 4574: [Zjoi2016]线段树

    Description 小Yuuka遇到了一个题目:有一个序列a_1,a_2,?,a_n,q次操作,每次把一个区间内的数改成区间内的最大值,问 最后每个数是多少.小Yuuka很快地就使用了线段树解决了 ...

  4. js获取客户端用户IP

    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> <script type=& ...

  5. webview中播放视屏,返回或者退出后,仍然会有声音。

    解决办法: protected void onPause() { super.onPause(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODE ...

  6. C# 获得word中某一段落所在页的页码

    方式一:通过openxml 从xml结构里获得不可行.原因如下A footer is not on a page and a page number in a footer is a field th ...

  7. 如何用 windows+github搭建一个优美的hexo博客

    1.Hexo简单介绍 Hexo 是一个快速.简洁且高效的博客框架.Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页. 风一般的速度Hexo基于Nod ...

  8. 线程的Interrupt方法与InterruptedException解析

    线程阻塞状态与等待状态(当一个线程处于被阻塞或等待状态时,它暂时不活动,不允许任何代码且消耗最少的资源) 当一个线程试图获得一个内部的对象锁(而不是java.util.concurrent库中的锁), ...

  9. 选择排序——Java实现

    一.排序思想 选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理是: 从待排序列中选出最小(或最大)的一个元素,记录其下标(数组)的位置: 将记录的下标值与待排序列的第一个 ...

  10. 设计模式之职责链模式(JAVA实现)

    学习netty框架时,看到有人说netty用到了设计模式的职责链模式,学习一下职责链模式,主要参考大话设计模式. 主要场景: 小菜想要加薪,向经理提出加薪请求,经理没有权限,经理交由总监处理,总监也没 ...