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. Python学习:15.Python面向对象(二、继承的各种情况)

    一.什么是继承 继承是一种创建类的方法,在python中,一个类可以继承来自一个或多个父.原始类称为基类或超类. #创建父类 class Parent1: pass class Parent2: pa ...

  2. IP组播 MulticastChannel接口 DatagramChannel实现

    监听者 import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; impo ...

  3. uva 156 - Ananagrams (反片语)

    csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找 ...

  4. [转载]DotNetty 学习

    [转载]http://www.cnblogs.com/littlegod/p/7699482.html DotNetty的学习是带着如下这些问题展开: 1. Socket基础框架方案: 通信模式:异步 ...

  5. windows phone 8.1 让项目开启蓝牙genericAttributeProfile

    1.打开项目里面的  Package.appxmanifest 文件 找到<Capabilities>节点,添加代码如下,其中 serviceId:6006 可以自己修改值 <m2: ...

  6. 【转载】C/C++杂记:NULL与0的区别、nullptr的来历

    原文:C/C++杂记:NULL与0的区别.nullptr的来历 某些时候,我们需要将指针赋值为空指针,以防止野指针.   有人喜欢使用NULL作为空指针常量使用,例如:int* p = NULL;. ...

  7. java程序运行中如果出现异常未被处理,将会被抛到java虚拟机进行处理,程序中断运行后被挂起,在页面输出错误信息(不会输出到console)

    下面的代码中,因为我是使用 for (Iterator<Element> i = el.elements().iterator(); i.hasNext(); ) 迭代器遍历根节点的所有子 ...

  8. idea 从javadoc中复制内容出来

    打开 tool window就行了 经验:百度google不到的东西太多了,要学会自己想办法,至少也要把功能都试一遍吧, 而且像这种东西官方一般会给方法实现你的目的,只不过有时候是把功能迁移了或者整合 ...

  9. bootstrap 4 panels已被card替换

    https://www.zhihu.com/question/34838389?sort=created 解决问题的思路不对,不应该搜不到就各种着急,应该理清思路, 既然 bootstrap4没有了3 ...

  10. Airflow使用入门指南

    Airflow能做什么 关注公众号, 查看更多 http://mp.weixin.qq.com/s/xPjXMc_6ssHt16J07BC7jA Airflow是一个工作流分配管理系统,通过有向非循环 ...