1063 Set Similarity (25 分) set注意查询从1到q所以输入的时候也要从1到n
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:
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%
#include <cstdio>
#include <set>
using namespace std;const int N = 51;
set<int> st[N];void compare(int x, int y) {int totalnum = st[y].size();int 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 totalnum++;}printf("%.1f%\n", samenum*100.0 / totalnum);}int main() {int n,m,x,q,a,b;scanf("%d", &n);for (int i = 1; i <= n; i++) {//这里必须从1开始,因为查询的时候scanf("%d", &m);for (int j = 0; j < m; j++) {scanf("%d", &x);st[i].insert(x);}}scanf("%d", &q);for (int i = 0; i < q; i++) {scanf("%d%d", &a, &b);compare(a, b);}return 0;}
1063 Set Similarity (25 分) set注意查询从1到q所以输入的时候也要从1到n相关推荐
- 【最后测试点超时】1063 Set Similarity (25 分)_22行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given two sets of integers, the similarity of the sets is defined ...
- 1063 Set Similarity (25 分)【难度: 一般 / 知识点: STL中set的应用】
https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 可以很容易的写出一个最暴力的写法.可以骗21 ...
- 1063 Set Similarity (25 分) java 题解
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Nc is t ...
- 1063. Set Similarity (25)
题目例如以下: Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc ...
- 1063 Set Similarity
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...
- PTA---航空公司VIP客户查询 (25分)---Stl-Map容器简单使用
Map是STL的一个关联容器,它提供一对一(也就是一个键一个值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道.map内部自建一颗红黑树(一种非严格意义上的 ...
- 7-15(查找) 航空公司VIP客户查询(25 分)
7-15(查找) 航空公司VIP客户查询(25 分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员 ...
- 7-15 航空公司VIP客户查询 (25分)(没用stl,哈希链地址法实现)
7-15 航空公司VIP客户查询 (25分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员的飞行记 ...
- # 7-45 航空公司VIP客户查询 (25 分)
7-45 航空公司VIP客户查询 (25 分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员的飞行 ...
- 7-45 航空公司VIP客户查询 (25 分)
7-45 航空公司VIP客户查询 (25 分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员的飞行 ...
最新文章
- 源码编译安装percona-xtrabackup-2.3.2
- DL之CNN:利用CNN算法实现对句子分类+进行情感分析(预测句子情感)
- woe分析_Python数据分析—apply函数
- WIN7与WIN10 安装
- Python使用元类约束派生类中必须实现指定的成员
- java类加载器正确的是_Java面试题:面向对象,类加载器,JDBC, Spring 基础概念
- mac 安装php7.4
- 028 kafka面试小节
- XZ_iOS iOS13浅色模式/暗黑模式导航栏颜色不自动适配
- ZooKeeper 客户端: GUI+命令行两大类(史上最全,值得收藏)
- 2021-04-23 - TS型网页视频下载 - 学习/实践
- 哲学家就餐问题-中断解决
- RuntimeError: mat1 and mat2 shapes cannot be multiplied (192x64 and 4x3)
- python人工智能方向入门书籍推荐_python 人工智能 入门要看那些理论书
- python制作微信个人二维码怎么做_如何用Python制作微信的好友背景墙?
- 【练习】获取新浪搜索中的热搜榜的标题
- 利弗莫尔的操作系统到底是怎样的?
- android棉花糖,清甜棉花糖:安卓M/Android 6.0上手体验评测
- 【操作系统】进程-哲学家进餐问题
- 林深时见鹿,海蓝时见鲸
热门文章
- Android中实现两次点击返回键退出本程序
- *(volatile unsigned long *) 语法
- Office 365系列(1)------Office 365邮箱申请及初步配置说明
- MySQL基础与操作
- linux内核升级到3.4
- avue 文字点击 弹窗_目前最好用的文字转语音、视频配音方法,一键合成,智能黑科技...
- hadoop api 复制文件_Hadoop核心架构是怎样的?
- excel在线_如何把pdf转excel将文档保持原有格式
- SpringBoot Maven repackage failed: Unable to find a single main class from the following candidates
- SpringBoot整合jsp的使用