代码编织梦想

本题的大意就是两个集合的交集除以两个集合的并集 结果用百分比表示并且保留一位小数

这道题主要需要注意的是输出 两个int转百分比需要强转成double 以及%的转义字符是两个%%比较特殊需要记忆

遇到一些疑惑的点就是多调试 试一试就知道行不行 不行就找bug学会就好了

ac代码:

#include<iostream>
#include<set>
using namespace std;
const int N=70;
set<int> p[N];
int main()
{
    int n,m;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>m;
        for(int j=0;j<m;++j)
        {
            int x;cin>>x;
            p[i].insert(x);
        }
    }
    cin>>m;
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        int cnt=0;
        for(auto s:p[a]) cnt+=p[b].count(s);
        int count=p[a].size()+p[b].size()-cnt;
        printf("%.1lf%%\n",(double)cnt/count*100);
    }
    return 0;
}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_57260823/article/details/129479857

pat 甲级 1063 set similarity(25 分)_uknownothing_的博客-爱代码爱编程

1063 Set Similarity(25 分) Given two sets of integers, the similarity of the sets is defined to be N​c​​/N​t​​×100%, where N​c​​ is the number of distinct common numbers shared by

pat甲1063 set similarity(25 分)_所谓刹那的博客-爱代码爱编程_pat甲1063

#include <string.h> #include <stdio.h> #include <algorithm> #include <string> #include &

pat a1063 set similarity+set初探_一只小菜猪的博客-爱代码爱编程

Given two sets of integers, the similarity of the sets is defined to be N​c​​/N​t​​×100%, where N​c​​ is the number of distinct common numbers shared by the two sets, and N​t​​ is

pat a1063 set similarity (25 分) set_hackinggate的博客-爱代码爱编程

    题目大意:给出N个集合,输出指定集合 m 和 n 的相似度。所谓相似度,是指 集合 m 和 n 中公共的元素的个数(不重复),占 m 和 n中所有不同元素个数的百分比。     可以直接用set<int> 存储 集合 m 和 n,之后将它们的元素再插入一个新的集合中,这样可以得到它们总的不重复元素个数和公共元素个数。不过这样虽然在PA

PAT A 1063 Set Similarity (25分)-爱代码爱编程

一、思路 1、使用set作为数据结构存储集合,利用set自动去重的特性; 2、Nc及Nt的计算: Nt初始设为集合一中不同元素数,遍历集合二,若某元素不在集合一中,++Nt,否则++Nc; 结果即Nc / Nt * 100%; 3、显然使用unordered_set比set效率要高(但均不会超时) 二、代码 #include <cstdio

关于PAT A1063 Set Similarity的记录-爱代码爱编程

Given two sets of integers, the similarity of the sets is defined to be Nc/N​t×100%, where N​c is the number of distinct common numbers shared by the two sets, and N​t is the tota

PAT A1063 Set Similarity (25分)-爱代码爱编程

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 题目描述 Given two sets of integers, the similarity of the sets is defined to be N​c​​ /N​t​​ ×100%

PAT A1063 Set Similarity (25point(s))-爱代码爱编程

题目链接 注意点: 1.要滤掉集合中的相同元素,因此使用set比较方便。 2.比较两集合时因遍历其中一个集合的每个元素,与另一个集合中的元素比较,用find()来查找时间复杂度可以到O(n(a)logn(b)),如果处理两个集合,时间复杂度会到O(N^2),最后一个样例会超时。 AC代码: #include<cstdio> #include&

PAT A 1063 Set Similarity-爱代码爱编程

#include<iostream> #include<set> using namespace std; int main() { int n,m,number; cin>>n; set<int> v[n+1]; for(int i=1;i<=n;i++){

PAT A1063 Set Similarity (25)-爱代码爱编程

PTA跳转:原题链接 题目大意是:比较两个集合的相似性。 输入:先输入一个数字m,然后要输入m组数据。接着输入一个数字n,然后输入n对数字。 输出:输出n个百分比数据。 本题考点是set,因为set容器内部元素有序且不重复,不用担心输入数据时有重复的元素。 我认为难点在于对题目,尤其是Nt的理解,原文“Nc is the number of di

PAT-A-1063 Set Similarity 【set】-爱代码爱编程

Given two sets of integers, the similarity of the sets is defined to be N​c​​/N​t​​×100%, where N​c​​ is the number of distinct common numbers shared by the two sets, and N​t​​ is

【unordered_set】PAT A1063 Set Similarity (25分)-爱代码爱编程

文章目录 题目描述知识点我的实现码前思考代码实现码后反思 题目描述 知识点 STL中的无序集合unordered_set 我的实现 码前思考 这里我使用的是暴力遍历两个set到一个set里面,然后比较前后值的个数的变化,得到公共的部分。 需要注意的是,千万不能两层for循环遍历,那样绝对会超时! 代码实现

PAT A1063 Set Similarity (25 分)-爱代码爱编程

目录 题目注意点实现 题目注意点 本题需要去除重复数字,因此用set做很方便find()函数找不到时返回end(),用作判断条件实现 #include <stdio.h> #include <set> using namespace std; double cmp(set<int> a, set<i

pixhawk rpi cm4 baseboard 树莓派cm4安装ubuntu20.04 server 配置ros mavros mavsdk-爱代码爱编程

文章目录 硬件安装Ubuntu Server20.04下载rpiboot工具下载imager 刷写系统配置USB配置WIFI开机安装桌面配置wifi配置串口安装ROS安装mavros安装MAVSDK-Python

c++回顾(十七)—— 类型转换-爱代码爱编程

17.1 static_cast(expr) static_cast强制类型转换 用于基本类型间的转换,但不能用于基本类型指针之间的转换 用于有继承关系类对象之间的转换和类指针之间的转换 static_cast是在编译

2.2.i2c编程实践-爱代码爱编程

linux内核I2C驱动代码中的一些重要结构体: 一般一条I2C总线上,主设备即I2C控制器,一般由i2c_adapter对其进行描述,一般有nr描述它是第几个I2C控制器(第几条总线),而大家都知道I2C控制器提供读写能力,它内部一定会有数据传输的函数(包含在i2c_algorithm算法结构体中)。 struct i2c_adapter { st

【c++】树状数组-爱代码爱编程

定义: 所谓树状数组,逻辑结构是一棵树,但是采用数组实现,他能解决单点修改区间查询类的问题,属于前缀和的一种优化。 lowbit: 学习树状数组,首先要引入lowbit 概念,所谓 lowbit,指的是二进制数最低位的1的权值,比如二进制数1100的lowbit就是二进制表示就是100,也就是权值为2^2 = 4,下文中我们用lowb

快速排序的基本思想(图文详解)-爱代码爱编程

文章目录 前言一、(1)首先设定一个分界值,通过该分界值将数组分成左右两部分。二、(2)将大于或等于分界值的数据集中到数组右边,小于分界值的数据集中到数组的左边。此时,左边部分中各元素都小于分界值,而右边部分中各元素