1063 Set Similarity (25 分)
 

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 Klines 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%
作者: CHEN, Yue
单位: 浙江大学
时间限制: 500 ms
内存限制: 64 MB

题意:

本题定义集合相似度Nc/Nt*100%,其中Nc是两个集合中共有的不相等元素个数,Nt是两个集合中不相等元素的个数。你的任务是计算给定的集合的相似度。

Nc是两个集合的交集元素数量。
Nt是两个集合的并集元素数量。

题解:

本来用数组,明显内存超限,速学了set,很方便啊!!!一下子过了。

printf 输出%,要%%

AC代码:

#include<iostream>
#include<set>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
set<int>s[];
int n,m,k;
int main(){
cin>>n;
for(int i=;i<=n;i++){
cin>>m;
for(int j=;j<=m;j++){
int x;
cin>>x;
s[i].insert(x);
}
}
cin>>k;
for(int i=;i<=k;i++){
int a,b;
cin>>a>>b;
set<int>::iterator it;
int count=;
for(it=s[a].begin();it!=s[a].end();it++){
if(s[b].find(*it)!=s[b].end()) count++;
}
printf("%.1f%%\n",count*1.0/(s[a].size()+s[b].size()-count)*);
}
return ;
}

PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)的更多相关文章

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

  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 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

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

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

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

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

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

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

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

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

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

随机推荐

  1. python中set(集合),深浅拷贝以及一些补充知识点

    1.set集合 特点:无序,不重复,元素必须可哈希(不可变) 作用:去重复 本身是可变的数据类型.有增删改查操作.{集合的增删改查操作应用较少,这里不做详细介绍了(这里的增有一个方法update注意这 ...

  2. 【搜索-剪枝-偏难】PAT-天梯赛-L3-015. 球队“食物链”

    L3-015. 球队“食物链” 某国的足球联赛中有N支参赛球队,编号从1至N.联赛采用主客场双循环赛制,参赛球队两两之间在双方主场各赛一场. 联赛战罢,结果已经尘埃落定.此时,联赛主席突发奇想,希望从 ...

  3. CentOs 6语言改成中文

    1.在root权限下 切换到root下:su - root 查看当前语言环境:locale -a  (注意中间有空格) 如果看到 zh_CN.UTF-8(这个是中文简体)说明你的系统支持中文语言: 没 ...

  4. 19 使用Vue实例的render方法渲染组件

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. TCL服务器端

    import socket def main(): # 创建套接字对象 tcp_server_socket = socket.socket(socket.AF_INET,socket.SOCK_STR ...

  6. go语言的内建变量类型

    string bool int int8  int16 int32 int64 uintptr   无符号int 类型  (u)int (u)int8 (u)int16 (u)int32 (u)int ...

  7. Define Interfaces and Share Class Members through Mixins in Dart

    In this lesson, we will cover Interfaces and Mixins. Interfaces act as a contract containing propert ...

  8. js与json的区别,json的概述,json与面向对象,json与对象的转换

    <script> //js与json的区别,json的概述,json与面向对象,json与对象的转换 //json的概述:json(javascript object Notation,j ...

  9. 代码 | 自适应大邻域搜索系列之(6) - 判断接受准则SimulatedAnnealing的代码解析

    前言 前面三篇文章对大家来说应该很简单吧?不过轻松了这么久,今天再来看点刺激的.关于判断接受准则的代码.其实,判断接受准则有很多种,效果也因代码而异.今天介绍的是模拟退火的判断接受准则.那么,相关的原 ...

  10. 原生table表格的使用

    近期公司让我修改一些之前的table标签写的页面,感觉对table相关的标签不是太熟悉,于是专门整理一下: 1.如果给td标签设置百分比宽度,比如有10列内容,我们却设置了每个单元格是30%的宽度,会 ...