PAT甲级 - 1107 Social Clusters (30 分) 并查集

MAX31855电路和程序,实现SPI和软件模拟时序两种方式读取数据 1. 概述 MAX31855为热电偶至数字输出转换器,内置14位模/数转换器(ADC)。器件带有冷端补偿检测和修正、数字控制器、SPI兼容接口,以及相关的控制逻辑,在温度控制器、过程控制或监测系统中设计用于配合外部微控制器(μC)工作。提供多个版本的器件,每个版本针对特定的热电偶类型(K、J、N、T或E型)进行优化和调整。热电偶类型以器件型号后缀表示(例如MAX31855K)。 器件输出14位... 阅读详情

When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of their hobbies in common. You are supposed to find all the clusters.

Input Specification:

Each input file contains one test case. For each test case, the first line contains a positive integer N (≤1000), the total number of people in a social network. Hence the people are numbered from 1 to N. Then N lines follow, each gives the hobby list of a person in the format:

K​i​​: h​i​​[1] h​i​​[2] ... h​i​​[K​i​​]

where K​i​​ (>0) is the number of hobbies, and h​i​​[j] is the index of the j-th hobby, which is an integer in [1, 1000].

Output Specification:

For each case, print in one line the total number of clusters in the network. Then in the second line, print the numbers of people in the clusters in non-increasing order. The numbers must be separated by exactly one space, and there must be no extra space at the end of the line.

Sample Input:

8
3: 2 7 10
1: 4
2: 5 3
1: 4
1: 3
1: 4
4: 6 8 1 5
1: 4

Sample Output:

3
4 3 1

并查集,father[], course[], isRoot[],三个数组

course[]记录喜欢相同课程的人,发现冲突,则合并

father[]将喜欢相同课程的人合并。

isRoot[]结合FindFather,记录每个cluster的人数

思想上很简单,实现起来真的不容易,想说爱你不简单

#include<cstdio>
#include<algorithm>
using namespace std;
int n;
const int maxn = 1010;
int father[maxn], course[maxn] = { 0 }; // course[i]表明喜欢course[i]的人
int isRoot[maxn] = { false };

int FindFather(int i) {
	//int z = i;
	while (i != father[i]) {
		i = father[i];
	}
	return i;
}

void Union(int a, int b) {
	int faA = FindFather(a);
	int faB = FindFather(b);
	if (faA != faB) {
		father[faA] = faB;
	}
}

void Init(int n) {
	for (int i = 1; i <= n; i++) {
		father[i] = i;
	}
}

bool cmp(int a, int b) {
	return a > b;
}
int main() {
	scanf("%d", &n);
	int v, k;
	Init(n);
	for (int i = 1; i <= n; i++) {
		scanf("%d:", &k);
		for (int j = 0; j < k; j++) {
			scanf("%d", &v);
			if (course[v] == 0) {
				course[v] = i;
			}
			else {
				Union(i, course[v]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		isRoot[FindFather(i)]++; //明确每个所属的团体
	}
	int num = 0;
	for (int i = 1; i <= n; i++) {
		if (isRoot[i] != 0) num++;
	}
	printf("%d\n", num);

	sort(isRoot + 1, isRoot + n + 1, cmp);

	for (int i = 1; i <= num; i++) {
		if (isRoot[i] != 0) {
			if (i != 1)
				printf(" ");
			printf("%d", isRoot[i]);
		}
	}
}

 

从X86到ARM:将VINS-Fusion-GPU和ego-planner迁移到Jetson Orin-NX时,我踩过的那些‘环境差异’坑 本文详细介绍了将VINS-Fusion-GPU和ego-planner从X86平台迁移到Jetson Orin-NX(ARM架构)时遇到的环境差异问题及解决方案。内容涵盖ARM与X86的架构差异、依赖管理、性能调优和硬件接口适配,特别强调了CUDA在ARM平台上的优化配置和内存访问技巧,帮助开发者高效完成跨平台迁移。 阅读详情

相关推荐

避坑指南:RK3576+Android14适配移远5G模组(RG200U)时,我遇到的3个‘巨坑’及解决方案

本文详细记录了RK3576芯片适配Android14系统与移远RG200U 5G模组过程中遇到的三大技术难题:RIL服务启动失败、HIDL兼容性矩阵配置错误及ttyUSB权限冲突。通过实战案例提供了动态库拷贝、HIDL版本链声明和SELinux策略调整等解决方案,帮助开发者高效完成5G模组集成,特别适用于基于kernel6.1的嵌入式开发场景。

weixin_30664051的博客 391

ISE MAP出错:Pack:1107 - Pack was unable to combine the symbols listed below into a single IOB33 compon

Pack:1107 - Pack was unable to combine the symbols listed below into a single IOB33 component because the site type selected is not compatible. Further explanation: The component type is determined by...

swang_shan的博客 1万+

Cursor插件安装CodeX保姆级教程:从登录到调整面板布局,一步不落

本文提供Cursor编辑器安装CodeX插件的详细教程,涵盖从登录到调整面板布局的全流程。通过优化界面布局和配置参数,帮助开发者提升编码效率,特别适合需要智能代码补全的编程场景。

weixin_42648844的博客 4775

初入FPGA之ISE遇到的问题(1)

1.编译时出现报错:ERROR:Pack:1107 - Pack was unable to combine the symbols listed below into a   single IOB component because the site type selected is not compatible.即名字为IP_LXXX_X的引脚只能作为专用输入引脚,而不能作为输出引脚。这是我在...

要恰饭得嘛 4751

UDS诊断入门第一课:手把手教你玩转0x10会话控制服务(附ISO14229实战解析)

刚接触汽车电子诊断的工程师们,往往会被厚厚的ISO 14229标准文档和各种专业术语吓退。但就像学习编程要从"Hello World"开始一样,掌握UDS协议的最佳切入点就是0x10诊断会话控制服务。这个看似简单的服务,实际上是整个诊断系统的"钥匙"——它决定了ECU(电子控制单元)当前处于何种工作模式,直接影响着其他诊断服务的可用性。 在实际车辆诊断中,ECU默认处于DefaultSession模式,这种模式下许多高级诊断功能是被禁用的。想象一下你正在开发一个需要刷写ECU固件的工具,如果连最基本的会

weixin_30402343的博客 394

位置点位到达判断FC(Easy+Codesys+博途平台)

IN rActPositon REAL 轴当前实际位置 1IN arAbsPosition REAL[10] 各工作点位坐标 2IN rDeadZone REAL 位置达到判断域值 范围 3OUT abInAbsPos BOOL[10] 到达各绝对定位点位标志 位置到达输出 4VAR i INT 循环计数 5VAR rErr REAL 位置偏差 6。

RXXW_Dor的博客 537

PAT——1107 Social Clusters 甲级(并查集)

1107 Social Clusters题目题意代码解析AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805361586847744 题意 给出n个学生各自的爱好,拥有相同爱好的同时视为在同一个社交网络中。本题需要求出社交网络总数,并按降序输出每个社交网络的人数 代码解析 find和combine都是并查集的老朋友了,不太了解的同学可以在优快云上自学一下并查集。其中find函数的代码是和参考文章不同的,我采用

ljhsq的博客 277

ABAP CDS View 从入门到精通教程第一篇:ABAP CDS View 在 SAP 技术体系中的重要地位

摘要:本文介绍了SAP开发技术专家提供的多套SAP开发教程,涵盖ABAP、UI5、Fiori、OData、BTP等技术领域。重点阐述了ABAP CDS View在SAP S/4HANA中的核心地位,作为虚拟数据模型(VDM)的关键技术,它实现了OLTP和OLAP的统一处理。文章还说明了学习CDS View的前置条件,包括需要SAP NetWeaver 7.50 SP01或更高版本系统,以及使用SAP ABAP Development Tool进行开发实践。作者具有16年SAP开发经验,这些教程形成了完整的S

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 899

Xilinx ISE 14.7 ERROR:Pack:1107

报错场景:基于Xilinx Spartan6 XC6SLX9平台,使用ChipScope采集AD模数转换端口接收到的波形,在.v代码中使用了“(*KEEP = "TRUE"*)wire XXXXXXX(信号名);”语句不是100%会报错(同样的代码之前在XC6SLX16下未见此报错情况),而且看网上感觉ERROR:Pack:1107出现的原因都不一样,故在此记录,如有谬误,烦请各位大佬不吝赐教。”语句,会在.ucf约束文件中添加对应信号的Keep true XXXXXXX(信号名)语句,导致编译报错。

Zealero的博客 790

CANoe如何实现TLS协议

TLS,Transport Layer Security,传输层安全协议。是在传输层和应用层之间,为了保证应用层数据能够安全可靠地通过传输层传输且不会泄露的安全防护。

jasonj333 1167

关于 Nginx 监听地址 0.0.0.0 的详细解释

0.0.0.0在Nginx配置中表示监听服务器所有网络接口(包括公网IP、内网IP和本地回环地址),这是默认配置。当使用listen 80;时,Nginx会接受通过服务器任何IP地址的80端口访问请求。相比只监听特定IP,这种配置更通用,但也意味着服务会对外网开放,需注意安全风险。可通过netstat命令验证监听状态,显示0.0.0.0:80即表示正确配置。

weixin_43674738的博客 1567

ISE使用过程中遇到的一个诡异问题

今天在使用ISE进行工程编译时发现一个诡异的问题,提示信息如下: ERROR:Pack:1107 - Pack was unable to combine the symbols listed below into a    single IOB component because the site type selected is not compatible.  起初怀疑是原理图设计

as0430的专栏 1万+

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

甲级PAT 1107 Social Clusters (30 分)(并查集)

1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of...

Joyceyang_999的博客 237

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

PAT 甲级 1107 Social Clusters (30分)(并查集)

1107Social Clusters(30分) When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. Asocial cluster...

蔡军帅 490

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

【PAT甲级】1107 Social Clusters (30 分)【并查集】

【PAT甲级】1107 Social Clusters (30 分)【并查集】 思路 如果两个人拥有相同的爱好,那么他们就在一个网络里。比如a,b有相同爱好1,b,c有相同爱好2,那么a,b,c在相同网络里 先把输入存下来,可以开一个大小为N的vector数组,保存第1-1000个爱好的人 如图,对于编号1-1000的爱好,每个爱好都有一个vector用来存储对应的人 遍历每个爱好,将同一个爱好中的人进行并查集的合并操作 从1-n遍历每个人,find(i)表示i节点的祖宗节点 c

郭同学如是说 167

pat 甲级 并查集 A1107 Social Clusters (30分)

1107 Social Clusters (30分) When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of their hobbies in common. You are

weixin_42358356的博客 192

PAT 甲级 1107 Social Clusters (30分)(并查集)

思路: 1.先用并查集算出所有交友圈集合; 2.再挨个遍历每个用户,查询他在哪个集合,相应集合数量++,最后数量倒序输出即可; 代码: #include<bits/stdc++.h> using namespace std; const int maxn=1005; int n,par[maxn],rnk[maxn],tag[maxn],peo[maxn]; void init_(...

Yuhan的博客 245

PAT甲级1107 Social Clusters (30分) 以及 牛客-并查集的实现 ,以及速度改进

链接:https://www.nowcoder.com/questionTerminal/e7ed657974934a30b2010046536a5372 来源:牛客网 给定一个没有重复值的整形数组arr,初始时认为arr中每一个数各自都是一个单独的集合。请设计一种叫UnionFind的结构,并提供以下两个操作。 boolean isSameSet(int a, int b): 查询a和b这两个数是否属于一个集合 void union(int a, int b): 把a所在的集合与b所在的集合合并在一起,原

qq_32691667的博客 317

PAT甲级 1107 Social Clusters (30分)(并查集)

传送门: 思路:题目中要求只要两个人有任意相同兴趣,那么他们就能被分到一组,于是可以记录每种兴趣对应的人(兴趣可以对应多个人,但是这里随便记录就行,只要有就可以之后进行合并了),之后遍历每个人的兴趣,根据兴趣对应的人合并即可,具体请参考代码。 代码: #include <bits/stdc++.h> using namespace std; const int maxn = 1005; int ans[maxn]; int cnt[maxn]; int p[maxn]; vector &l

一只谜谜怪的博客 217

PAT甲级 1107 Social Clusters (30 分)并查集

1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of...

qq_29762941的博客 365

PAT甲级1107 Social Clusters (30 分):[C++题解]并查集,爱好、人数

刷题

阿正的梦工坊 431

【PAT甲级】1107 Social Clusters(30 分)(并查集)

题目链接 When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of...

feng_zhiyu的博客 507

1107 Social Clusters (30 分) 【PAT甲级 非传统并查集 C++写法】

不用传统的并查集 用CLuster的map来创建 [集合编号:集合的映射] ,用每一个人的编号来作为集合的编号,也就是Cluster中的键(第一个进入集合的人的编号就是集合的编号(也可以理解为并查集中的根节点)); 用id数组来记录每一个人所在的集合的编号(也可以理解为并查集中的根节点) # include <bits/stdc++.h> using namespace std; int N; vector<int> hobby[1010]; vector<int>

MYMarcoreus的博客 225

PAT甲级--1107 Social Clusters(30 分)【并查集】

1107 Social Clusters(30 分) When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of ...

Imagirl1的博客 675

PAT (Advanced Level) Practice A1107 Social Clusters (30 分)(C++)(甲级)(并查集)

原题链接:A1107 Social Clusters #include&lt;algorithm&gt; #include&lt;iostream&gt; #include&lt;cstdio&gt; using namespace std; const int MAX = 1001; int i, N, K; int father[MAX], cnt[MAX] = {0}, hobby[MAX...

izhxxx的博客 213

PAT甲级真题 1107 Social Clusters (30分) C++实现(并查集:路径压缩+优先级)

题目 When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of their hobbies in common. You are supposed to find all th

zhang35的博客 277
上一篇: PAT甲级1066 Root of AVL Tree (25 分)
下一篇: PAT甲级 - 1098 Insertion or Heap Sort (25 分) 堆排序,找规律
DedicateToAI
博客等级 码龄9年 6粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值