【PAT甲级】1063 Set Similarity (25 分)
题意:
输入一个正整数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 分)的更多相关文章
- 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 ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 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 ...
- 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 ...
- PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other ...
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
- PAT 甲级 1028 List Sorting (25 分)(排序,简单题)
1028 List Sorting (25 分) Excel can sort records according to any column. Now you are supposed to i ...
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
随机推荐
- 各技能DBC参数
推荐你 通过 引擎的帮助文件查找标准魔法DB 下面是 部分hero引擎的标准魔法DB 34,解毒术,2,26,16,0,0,0,0,0,2,42,50,44,100,46,200,40,, 35,老 ...
- Box/坐标/方向/Row
1.Box, 我们在做design planning的第一步就是确定floorplan的box,也就是设计的区域.这个区域可以划分为三个边界,如下图所示: 上图中,按对应的颜色框框可以分为:Die B ...
- 给Python初学者的一些编程技巧
展开这篇文章主要介绍了给Python初学者的一些编程技巧,皆是基于基础的一些编程习惯建议,需要的朋友可以参考下交换变量 x = 6y = 5 x, y = y, x print x>>&g ...
- iframe子页面之间值传递
<div style="width:100%;height: 100%;"> <div style="width:74%;height: 70%;flo ...
- [爬坑记录] Qt 代码卡住 不发信号 不触发槽
先让我激动一会儿 [捂脸] 最近在用Qt做个程序 用来参加比赛 期间总共遇到两次如标题的问题 也即是 莫名其妙的不触发槽函数了 而且原因也不一样 {先说明 我学习Qt依旧只是入门级 也许入不了大佬法眼 ...
- pgspider http fdw http 相关的几个配置参数
http 请求时间配置 session 级别的 set http.timeout_msec = 10000; SELECT http_set_curlopt('CURLOPT_TIMEOUT', '1 ...
- 什么是this指针?this的几种指向
在JavaScript中,this指针是在创建时,由系统默认生成的两个隐式参数之一(另一个是arguments). this指针指向与该函数调用进行隐式关联的一个对象,该对象被称为“函数上下文”. t ...
- yii components文件到底应该放些什么代码
项目全局用的代码,比如项目所有controller和model的共通操作或者放一些第三方的组件.插件之类的项目全局用的代码
- python浅析对return的理解
函数外部的代码要想获取函数的执行结果,就可以在函数里面用return语句,把结果返回. return 代表一个函数的终止,如果return 后面带一个print 或者return ,则后面的不执行 ...
- 使用Canvas画布的注意事项
1.开始一个路径时要使用beiginPath()方法 ,不然会发生意想不到的事件. 2.图片加载完成后才能按照顺序依次绘图 (巧用onload时间)