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. mali tbr Forward Pixel Kill

    https://community.arm.com/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-20-66 ...

  2. collection,random,os,sys,序列化模块

    一.collection 模块 python拥有一些内置的数据类型,比如 str,list.tuple.dict.set等 collection模块在这些内置的数据类型的基础上,提供了额外的数据类型: ...

  3. nginx动静分离配置

    动静分离: 所谓动静分离指的是当访问静态资源时,路由到一台静态资源服务器,当访问是非静态资源时,路由到另外一台服务器 静态资源配置: 如配置如下location 表示url为  /static/*.x ...

  4. MongoDB 3.2变动一览

    3.2测试版本总算release了!E叔带大家来一览MongoDB 3.2版本的真容. (PS:内容比较多,在此仅针对个人认为比较重要的进行讲解,markdown写的,貌似WP的markdown插件有 ...

  5. 51nod 1459 & 1212

    1459 双限制最短路 #include <stdio.h> #include <iostream> #include <vector> #include < ...

  6. 主席树 Couriers

    [bzoj3524/2223][Poi2014]Couriers 2014年4月19日1,2571 Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r ...

  7. Hdu CRB and Queries(整体二分)

    CRB and Queries Time Limit: 6000 MS Memory Limit: 131072 K Problem Description There are N boys in C ...

  8. unity Assetboundle 工具

    Unity Asset Bundle Browser tool https://github.com/Unity-Technologies/AssetBundles-Browser assetboun ...

  9. BP神经网络原理及在Matlab中的应用

    一.人工神经网络 关于对神经网络的介绍和应用,请看如下文章 ​ 神经网络潜讲 ​ 如何简单形象又有趣地讲解神经网络是什么 二.人工神经网络分类 按照连接方式--前向神经网络.反馈(递归)神经网络 按照 ...

  10. 1 课务 iOS 概述

    重要注意 紫色解释 蓝色分类 新内容 CS193P 本课老版本 2010 年冬 http://open.163.com/movie/2010/6/C/7/M6RU83DCT_M6RU957C7.htm ...