https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928

Given two sets of integers, the similarity of the sets is defined to be /, where N​c​​ is the number of distinct common numbers shared by the two sets, and N​t​​ is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.

Input Specification:

Each input file contains one test case. Each case first gives a positive integer N (≤) which is the total number of sets. Then N lines follow, each gives a set with a positive M (≤) and followed by M integers in the range [0]. After the input of sets, a positive integer K (≤) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.

Output Specification:

For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.

Sample Input:

3
3 99 87 101
4 87 101 5 87
7 99 101 18 5 135 18 99
2
1 2
1 3

Sample Output:

50.0%
33.3%

代码:

#include <bits/stdc++.h>
using namespace std; int N, M; int main() {
scanf("%d", &N);
set<int> s[N + 1];
for(int i = 1; i <= N; i ++) {
int x;
scanf("%d", &x);
for(int j = 0; j < x; j ++) {
int y;
scanf("%d", &y);
s[i].insert(y);
}
} scanf("%d", &M);
while(M --) {
int a, b;
scanf("%d%d", &a, &b);
int num = 0;
for(set<int>::iterator it = s[b].begin(); it != s[b].end(); it ++)
if(s[a].find(*(it)) != s[a].end())
num ++; printf("%.1f%%\n", (double)num / (s[a].size() + s[b].size() - num) * 100);
}
return 0;
}

  前两天第一次交居然 0 !!!!! 今天才发现输出一位我输出两位。。。。 不用 set 会超时 

  后天出去玩 今天已经不是很想写了 哭唧唧

PAT 甲级 1063 Set Similarity的更多相关文章

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

  3. PAT甲级——A1063 Set Similarity

    Given two sets of integers, the similarity of the sets is defined to be /, where N​c​​ is the number ...

  4. pat(A) 1063. Set Similarity(STL)

    代码: #include<cstdio> #include<cstring> #include<set> using namespace std; set<i ...

  5. 1063 Set Similarity——PAT甲级

    1063 Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*10 ...

  6. PAT 1063 Set Similarity[比较]

    1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...

  7. PAT 1063. Set Similarity

    1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...

  8. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  9. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

随机推荐

  1. 从零开始搭建vue移动端项目到上线的步骤

    初始化项目 1.在安装了node.js的前提下,使用以下命令 npm install --g vue-cli 2.在将要构建项目的目录下 vue init webpack myproject(项目目录 ...

  2. S2-057远程代码执行漏洞复现过程

    0x01 搭建环境docker https://github.com/vulhub/vulhub/tree/master/struts2/s2-048 docker-compose up -d 0x0 ...

  3. ACM1008:Elevator

    Problem Description The highest building in our city has only one elevator. A request list is made u ...

  4. python 3下对stm32串口数据做解析

    1.最近有个想做一个传感器数据实时显示的上位机,常规的数据打印太频繁了,无法直观的看出数据的变化. python下的上位机实现起来简单一点,网上找了一些python界面Tkinter相关资料和pyth ...

  5. STM32F103C8T6、STM32F103ZET6工程模板

    STM32F103C8T6工程模板,推荐使用以下最新版本 最终版 2018 7 16  https://pan.baidu.com/s/1lIdZ2awus_quVu332RvJ6Q https:// ...

  6. C语言复习20170826

    数组 先定义,再初始化,最后使用. 访问数组中的元素可以采用数组名加下标的方式,下标是从0开始,c并不检查数组下标是否越界,所以在访问数组中的元素时需要注意,需要对数组下标做判断,防止访问数组越界. ...

  7. C#基础之反射

    虽然还在学校读书,反射实际写的不多.但感觉反射在程序开发中用得还是挺多的,对我来说也是.NET中的一个难点.通过反射,我们可以在运行时获得.NET中的每一个类型的成员,这些类型包括类.结构.委托和枚举 ...

  8. 【转载】3D/2D中的D3DXMatrixPerspectiveFovLH和D3DXMatrixOrthoLH投影函数详解

    原文:3D/2D中的D3DXMatrixPerspectiveFovLH和D3DXMatrixOrthoLH投影函数详解 3D中z值会影响屏幕坐标系到世界坐标系之间的转换,2D中Z值不会产生影响(而只 ...

  9. 洛谷 P1876 开灯

    传送门 这道题凭什么是! 就因为它代码短?! 还是我太菜了... 第$i$盏灯的开关与否只由其约数个数决定,又有约数公式: 当$n=p_1^{a_1}p_2^{a_2}...p_n^{a_n}$时,约 ...

  10. 用php做个简单的日历

    存档: index.php <html> <head> <title>日历</title> <style> table{border:1px ...