【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 ...
随机推荐
- 微信小程序 (组件的使用)
创建组件 在根目录创建components目录,然后创建列表组件 组件中内容 <view class="prolist"> //循环prolist列表 <view ...
- FreeRTOS学习笔记4:时间管理
绝对时间:abs Time相对时间:百分比% time IDLE是空闲任务. RUN_Time_State:port...()初始化一个外设提供时基单元 //具体初始化要自己操作这个定时器的分辨率高于 ...
- C# byte[]转string, string转byte[] 的四种方法
转载:https://blog.csdn.net/tom_221x/article/details/71643015 第一种 string str = System.Text.Encoding ...
- go使用错误概览
1. 解决:GO语言中要提供给外面访问的方法或是结构体必须是首字母大写.这个结构体只有结构体名大写了,而里面的字段没有首字母大写,而GO语言在模板调用时应该认为是两个不同的过程,所以找不到值.于是把结 ...
- lightoj 1408 概率dp
https://blog.csdn.net/moon_sky1999/article/details/98097470 博主在此,牛逼神犇 #include<bits/stdc++.h> ...
- 关于mybatis中sql映射文件模糊查询的使用
1.从前台传递一个String类型的参数到后台进行查询,如果牵涉到模糊查询会报错,应该把参数封装到对象中再进行传递然后进行模糊查询 2.一个查询框,多个查询条件 <if test="c ...
- Android 获取手机的厂商、型号、Android系统版本号、IMEI、当前系统语言等工具类
最近在开发中,需要用到一些系统信息,这里我把这些方法写成一个工具类方便以后复用,该工具类有以下6个功能: 1.获取手机制造厂商 2.获取手机型号 3.获取手机系统当前使用的语言 4.获取Android ...
- 自己centos7成功的修改了主机名(记录了该改哪些文件)
1.更改/etc/hosts 方法(1)可以直接的去更改这个文件,更改的格式:直接vi编辑器打开,之后直接写上自己想要的主机名字就好,不用写成键值对的形式 [root@localhost etc]# ...
- tomcat安装成功以后进行测试步骤:
tomcat安装成功以后进行测试步骤: 编写测试页面: 进入Tomcat安装对应路径: E:\Tomcat\apache-tomcat-8.5.45\webapps\ROOT 创建:test.jsp ...
- python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明。
python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明. 重难点:通过input函数输入的行消息为字符串格式,必须转换为整型,否则 ...