PAT (Advanced Level) Practise 1063 Set Similarity (25)
来源:互联网 发布:mac的显卡怎么样 编辑:程序博客网 时间:2024/06/15 07:09
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 number of distinct common numbers shared by the two sets, and Nt 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 (<=50) which is the total number of sets. Then N lines follow, each gives a set with a positive M (<=104) and followed by M integers in the range [0, 109]. After the input of sets, a positive integer K (<=2000) 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:33 99 87 1014 87 101 5 877 99 101 18 5 135 18 9921 21 3Sample Output:
50.0%33.3%
题意:给定两个整数集合,它们的相似度定义为:Nc/Nt*100%。其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数。就是计算任意一对给定集合的相似度
解题思路:set的应用
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <vector> #include <set> #include <stack> #include <map> #include <climits> using namespace std; #define LL long long const int INF=0x3f3f3f3f; int main() { int n; while(~scanf("%d",&n)) { int k,a; set<int>s[60]; for(int i=1;i<=n;i++) { scanf("%d",&k); for(int j=1;j<=k;j++) scanf("%d",&a),s[i].insert(a); } int m; scanf("%d",&m); while(m--) { int x,y; scanf("%d %d",&x,&y); set<int>::iterator it; int sum=0; for(it=s[x].begin();it!=s[x].end();it++) if(s[y].count(*it)) sum++; printf("%.1lf%%\n",1.0*sum/(s[x].size()+s[y].size()-sum)*100); } } return 0; }
- PAT (Advanced Level) Practise 1063 Set Similarity (25)
- PAT (Advanced Level) Practise 1063 Set Similarity (25)
- Pat(Advanced Level)Practice--1063(Set Similarity)
- 【PAT】【Advanced Level】1063. Set Similarity (25)
- 1063. Set Similarity (25)【集合操作】——PAT (Advanced Level) Practise
- 【C++ 】PAT(advanced level)1063. Set Similarity (25)
- PAT (Advanced Level) Practise 1113 Integer Set Partition (25)
- PAT (Advanced Level) Practise 1113 Integer Set Partition (25)
- PAT (Advanced Level) 1063. Set Similarity (25) set的相似度
- [PAT] (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- 端口号分类调研
- vue脚手架安装和使用
- ubuntu 16.04 源码安装samba并且配置
- logrotate与rsyslog基本使用
- VS2017 远程调试linux出现的错误:Cannot access memory at address 0x570
- PAT (Advanced Level) Practise 1063 Set Similarity (25)
- 自定义dialog点击区域外不消失、沉侵式状态下弹窗出现后无法覆盖标题栏,弹窗布局无法铺满屏幕问题
- mysql的字符集
- 工作中遇到的问题,借鉴别人的经验
- 堆(heap),栈(stack)和常量池、方法区
- Echarts 的option选项属性
- JavaScript 详说事件机制之冒泡、捕获、传播、委托
- 经典的IPC
- DNS 原理入门