PAT 1063. Set Similarity (25)
来源:互联网 发布:ios 数据库开发 编辑:程序博客网 时间:2024/06/10 13:45
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%
这道题就是考察集合,代码如下:
#include <iostream>#include <algorithm>#include <set>#include <iomanip>#include <cstring>using namespace std;int main(){int N,K,M;cin>>N;set<int> myset[N+1];for(int i=1;i<=N;i++){cin>>M;while(M--){int temp;cin>>temp;myset[i].insert(temp);}}cin>>K;while(K--){int s1,s2;cin>>s1>>s2;int count=0;int size=myset[s1].size()+myset[s2].size();set<int>::iterator it1=myset[s1].begin();set<int>::iterator it2=myset[s2].begin();for(;it1!=myset[s1].end()&&it2!=myset[s2].end();){if(*it1>*it2)it2++;else if(*it1<*it2)it1++;else{count++;it1++;it2++;}}cout<<setiosflags(ios::fixed)<<setprecision(1)<<count*100.0/(size-count)<<"%"<<endl;}}
- 1063. Set Similarity (25)-PAT
- pat 1063. Set Similarity (25)
- 【PAT】1063. Set Similarity (25)
- PAT 1063. Set Similarity (25)
- PAT 1063. Set Similarity (25)
- PAT 1063. Set Similarity (25)
- PAT 1063. Set Similarity
- 【PAT】1063. Set Similarity
- PAT--1063. Set Similarity
- PAT (Advanced) 1063. Set Similarity (25)
- PAT A 1063. Set Similarity (25)
- PAT(A) - 1063. Set Similarity (25)
- 【PAT甲级】1063. Set Similarity (25)
- 1063. Set Similarity (25) PAT甲级
- PAT甲级练习1063. Set Similarity (25)
- PAT甲级1063. Set Similarity (25)
- PAT-A-1063. Set Similarity (25)
- 【PAT】【Advanced Level】1063. Set Similarity (25)
- 06-图6. 公路村村通(30)--最小生成树-prime-kruskal
- Dijkstra算法
- CAP定理小议
- 如何判断一个数的二进制有多少个1
- 【最短路】【负圈可达点】【用while(!Q.empty())】【优先队列优化】【dij】
- PAT 1063. Set Similarity (25)
- Caliburn Micro Part 3: More About Events and Parameters
- 线段树的一系列应用
- Think in Java之构造器的真正调用顺序
- webService之hello级别中的注意事项
- andrioid EditText 光标设置为文本的末尾
- Android平台aac谷歌软解框架和流程、解码库学习
- mysql数据库学习笔记 -- Mysql解决
- CSS 字体代码