题意:

输入一个正整数N表示集合的个数(<=50),接着输入N行,每行包括一个数字x代表集合的容量(<=10000),接着输入x个非负整数。输入一个正整数Q(<=2000),接着输入Q行,每行包括两个数字代表集合的编号,每次询问输出两个集合的重复率(保留一位小数,重复率等于两个集合相同的数字个数除以两个集合合并为一个集合的话集合内数字的个数)。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[][];
set<int>st[];
int b[][];
int cnt[];
int main(){
int n;
cin>>n;
for(int i=;i<=n;++i){
int x;
cin>>x;
for(int j=;j<=x;++j){
cin>>a[i][j];
if(!st[i].count(a[i][j])){
st[i].insert(a[i][j]);
b[i][++cnt[i]]=a[i][j];
}
}
}
int q;
cin>>q;
while(q--){
int x,y;
cin>>x>>y;
if(cnt[y]<cnt[x])
swap(x,y);
int tamp=;
int sum=cnt[x]+cnt[y];
for(int i=;i<=cnt[x];++i)
if(st[y].count(b[x][i]))
++tamp;
double ans=100.0*tamp/(sum-tamp);
printf("%.1f%\n",ans);
}
return ;
}

【PAT甲级】1063 Set Similarity (25 分)的更多相关文章

  1. 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 ...

  2. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  3. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  4. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  5. PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)

    1059 Prime Factors (25 分)   Given any positive integer N, you are supposed to find all of its prime ...

  6. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

  7. PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)

    1048 Find Coins (25 分)   Eva loves to collect coins from all over the universe, including some other ...

  8. PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)

    1037 Magic Coupon (25 分)   The magic shop in Mars is offering some magic coupons. Each coupon has an ...

  9. PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

    1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to i ...

  10. PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

随机推荐

  1. 任务队列方案详解(一)JVM线程池

    前言 我们都知道 web 服务的工作大多是接受 http 请求,并返回处理后的结果.服务器接受的每一个请求又可以看是一个任务.一般而言这些请求任务会根据请求的先后有序处理,如果请求任务的处理比较耗时, ...

  2. Shell脚本命令汇总中

    一.换行 echo -e 可以通过\n编译换行 echo -n不换行,如果加入了\n,则会打出“\n”字符 #!/bin/bash echo -e "O\nK\n!" echo & ...

  3. 二叉树的详细实现 (C++)

    二叉树的定义     以递归形式给出的:一棵二叉树是结点的一个有限集合,该集合或者为空,或者是由一个根结点加上两棵分别称为左子树和右子树的.互不相交的二叉树组成.二又树的特点是每个结点最多有两个子女, ...

  4. python开发基础作业02:三级菜单,使用字典dic及列表

    作业要求及提示:三级菜单 ''' 1.三级菜单 2.可依次进入各子菜单 3.菜单能够回到上一级 4.用到知识点:字典.列表.多层循环.函数 条件:基本  if  else 嵌套  if...if... ...

  5. C语言随笔4:指针数组、数组指针

    数组: 1:数组名为地址,表达方法: Int A[10]; A;//数组名表示首地址 &A;//数组名加取地址符,仍然表示首地址 &A[0];//第0个元素的地址,即首地址 数组名是指 ...

  6. 普及C组第一题(8.9)

    2297. [noip普及组2(放到第一题)]棋盘 (好像重名了)(File IO): input:chess.in output:chess.out 题目描述 众所周知,国际象棋的棋盘是一个网格.国 ...

  7. MySQL 学习(二)总体框架 & redo-log 和 bin-log 的介绍

    文章部分总结来自课程,非原创 MySQL 组织架构     下面这张图就可以解释关于 MySQL 底层的组织架构了.     上面的图可以直观地展示两个重要的东西 : 一条 SQL 的执行流程 MyS ...

  8. 其他 - 02. poolmon 安装

    1. 概述 遇到 win10 的内存泄露 32G 内存都能给吃光 2. 思路 rammap 对整体内存做一个诊断 主要是内存分配 用途 状态 poolmon 确认内存的用途 比 rammap 更精确 ...

  9. const和defin区别

    (1)类型的安全性检查:const常量有数据类型,而define定义宏常量没有数据类型.则编译器可以对前者进行类型安全检查,而对后者只进行字符替换,没有类型安全检查(字符替换时可能会产生意料不到的错误 ...

  10. 时间戳,日期,string互转

    import timeimport datetimeimport operatordef makeStamp(y,m,d,format='%Y-%m-%d'): """m ...