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. P2280 [HNOI2003]激光炸弹[前缀和]

    题目描述 输入输出格式 输入格式: 输入文件名为input.txt 输入文件的第一行为正整数n和正整数R,接下来的n行每行有3个正整数,分别表示 xi,yi ,vi . 输出格式: 输出文件名为out ...

  2. redis--基于内存的高速缓存,NoSql的典型代表

    NoSql入门和概述 入门概述 为什么要使用NoSql? 1.单机mysql的美好年代 在早些年以前,那时候网站的访问量不大,用单个数据库完全可以应付.而且那个时候,绝大部分都是LAMP架构:Linu ...

  3. mysql - InnoDB存储引擎 死锁问题( Deadlock found when trying to get lock; try restarting transaction )

    刚刚向数据库插入数据的时候出现了这么一段错误 Deadlock found when trying to get lock; try restarting transaction 主要原因(由于无法使 ...

  4. POJ-2478-Farey Sequence(欧拉函数)

    链接: https://vjudge.net/problem/POJ-2478 题意: The Farey Sequence Fn for any integer n with n >= 2 i ...

  5. AirTest与模拟器连接(二)

    如果我们手边没有可用的Android真机,又想进行Android应用自动化测试,这时候就要使用AirtestIDE的Android模拟器自动化测试功能了. AirtestIDE所支持的模拟器包括 An ...

  6. [Dart] Dynamic variable in Dart

    First way to create dynamic variable is using 'dymaic' keywrod: dynamic a = 123; a = '123'; Second w ...

  7. tibco server keystore怎样使用多域名证书

    Create a Subject Alternative Name certificate with Active Directory Certificate Services https://kno ...

  8. Springboot项目使用junit-test(@Test)报错原因汇总

    1.不要随便改测试包名,我就是因为这个错的!!! 2.有的是pom.xml文件中引入了junit测试的两个jar包 3.其他问题百度就行

  9. TensorFlow(十三):模型的保存与载入

    一:保存 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #载入数据集 mnist ...

  10. spring boot aop 切库实现读写分离

    项目结构: 主要代码 : 配置数据库 配置datasource 线程隔离: 已上传git gitee地址:https://gitee.com/xxoo0_297/springboot-aop.git