PAT.1063A(set问题)
来源:互联网 发布:室内设计学习软件 编辑:程序博客网 时间:2024/06/07 18:24
问题描述
Set Similarity (25)
时间限制
300 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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:
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%
ac代码:
#include <bits/stdc++.h>using namespace std;const int maxn = 50+5;set<int> st[maxn];//maxn个集合void compare(int x, int y){ int totNum = st[y].size(), sameNum = 0; for(set<int>::iterator it = st[x].begin(); it!=st[x].end(); it++){ if (st[y].find(*it) != st[y].end()) sameNum++; else{ totNum++; } } printf("%.1f", sameNum*100.0/totNum); puts("%"); return;}int main(){ int n, k, x, y; int v; cin>>n; for (int i=1; i<=n; i++){//集合的序号是从1开始的 cin>>k; for (int j=0; j<k; j++){ cin>>v; st[i].insert(v); } } int q; cin>>q; for (int i=0;i<q; i++){ cin>>x>>y; compare(x, y); } return 0;}
- PAT.1063A(set问题)
- PAT-A-1063. Set Similarity
- PAT A 1063. Set Similarity (25)
- pat(A) 1063. Set Similarity(STL)
- PAT(A) - 1063. Set Similarity (25)
- PAT-A-1063. Set Similarity (25)
- PAT-1063 Set Similarity (set集合)
- 浙大PAT 1063题 1063. Set Similarity
- Pat(Advanced Level)Practice--1063(Set Similarity)
- PAT 1063. Set Similarity
- 【PAT】1063. Set Similarity
- PAT--1063. Set Similarity
- PAT (Advanced Level) Practise 1063 Set Similarity (25)
- PAT (Advanced Level) Practise 1063 Set Similarity (25)
- 找最大独立集问题-Finding a Maximal Independent Set
- 1063. Set Similarity (25)-PAT
- pat 1063. Set Similarity (25)
- 【PAT】1063. Set Similarity (25)
- (项目)AR电子书系统创新实训第四周(1)
- OpenShot 发布 2.3.2 版本啦!
- 【操作系统】页面置换算法
- 搜索--06
- 一个基于特征向量的近似网页去重算法——term用SVM人工提取训练,基于term的特征向量,倒排索引查询相似文档,同时利用cos计算相似度
- PAT.1063A(set问题)
- Java导出Excel表格
- Android6.0及以上版本申请权限讲解
- Java中关键字 static 与final 易错点
- 1.串口通信
- 一个基于特征向量的近似网页去重算法
- mac安装mysql
- 如何制作U盘启动盘(Ubuntu)
- 联想PC陷入困境 4月份笔电跌至全球第三