[PAT] A1063
来源:互联网 发布:cnrds数据库 编辑:程序博客网 时间:2024/06/07 03:24
link:https://www.patest.cn/contests/pat-a-practise/1063
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%
AC:
#include <iostream>#include <cstdio>#include <set>using namespace std;set<int> S[60];double cale(int a, int b){ int nt = S[b].size(), nc = 0;//nt = S[a].size()不对 for(set<int>::iterator it = S[a].begin(); it != S[a].end(); it++){ if(S[b].find(*it) != S[b].end()) nc++; else nt++; } return nc * 100.0 / nt;}int main(){ int num; cin >> num; for(int i = 1; i <= num; i++){ int number; cin >> number; for(int j = 0; j < number; j++){ int n; cin >> n; S[i].insert(n); } } cin >> num; while(num--){ int a, b; cin >> a >> b; printf("%.1lf%\n", cale(a, b)); } return 0;}
- [PAT] A1063
- PAT A1063
- PAT-A1063
- PAT a1063题解
- PAT-A1063. Set Similarity (25)
- pat-a1063. Set Similarity (25)
- PAT A1063. Set Similarity (25)
- PAT A1063 set similarity (25)
- A1063. Set Similarity (25)
- A1063. Set Similarity (25)
- A1063.Set Similarity
- 刷清橙OJ--A1063.求导函数
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- 多进程间通信方式和多线程同步机制总结
- 嵌入式实时操作系统ucos/ii 原理与应用(六)
- 神器BBMap
- Caffe使用step by step:caffe框架下的基本操作和分析
- Android获取手机已安装的应用程序并启动
- [PAT] A1063
- 第三周项目4--顺序表应用1
- 改变eclipse背景颜色
- Git(一)git/github简介
- Effective Java_中英文对照_第一章_2.0版本
- 三种主要嵌入式数据库
- centos 上安装监控流量软件
- (BFS/DFS)POJ 1979 Red and Black
- 线程池,是时候做个了结了!