pat 1118. Birds in Forest (25) 并查集

PID、模糊PID、SkyHook、LQR、H2/H∞、ADRC等悬架控制合集 PID、模糊PID、SkyHook、LQR、H2/H∞等悬架控制合集 阅读详情

1118. Birds in Forest (25)

时间限制
150 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in the forest, and for any pair of birds, tell if they are on the same tree.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive number N (<= 104) which is the number of pictures. Then N lines follow, each describes a picture in the format:
K B1 B2 ... BK
where K is the number of birds in this picture, and Bi's are the indices of birds. It is guaranteed that the birds in all the pictures are numbered continuously from 1 to some number that is no more than 104.

After the pictures there is a positive number Q (<= 104) which is the number of queries. Then Q lines follow, each contains the indices of two birds.

Output Specification:

For each test case, first output in a line the maximum possible number of trees and the number of birds. Then for each query, print in a line "Yes" if the two birds belong to the same tree, or "No" if not.

Sample Input:
4
3 10 1 2
2 3 4
4 1 5 7 8
3 9 6 4
2
10 5
3 7
Sample Output:
2 10
Yes
No


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>

using namespace std;

int N, Q;
int f[10005], a[10005];
int maxn, minn;
set<int> s;

int getf(int x) {
	return f[x] == x ? x : f[x] = getf(f[x]);
}

int main()
{
	cin >> N;
	for (int i = 1; i <= 10003; i++) {
		f[i] = i;
	}
	maxn = -1;
	for (int i = 0; i < N; i++) {
		int K;
		scanf("%d", &K);
		minn = 99999;
		for (int j = 0; j < K; j++) {
			scanf("%d", &a[j]);
			maxn = max(maxn, a[j]);
			minn = min(minn, a[j]);
		}
		for (int j = 0; j < K; j++) {
			f[getf(a[j])] = getf(minn);  //debug f[a[j]] -> f[getf(a[j])]
		}
	}
	for (int i = 1; i <= maxn; i++) {
		s.insert(getf(i));
	}
	printf("%d %d\n", s.size(), maxn);
	cin >> Q;
	while (Q--) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (getf(x) == getf(y)) {
			puts("Yes");
		}
		else {
			puts("No");
		}
	}
	return 0;
}




[QMT量化交易小白入门]-四十九、中小盘策略是否还有未来,市值再平衡策略,年化收益率124% 该策略旨在通过定期再平衡持仓,保持投资组合中股票数量恒定(),并优先持有市值较小的股票。具体来说,策略每两天(period = 2)进行一次再平衡,根据当前市值对持仓进行调整,以实现微盘股的投资目标。中小市值策略对资金量要求有限制,资金量太大由于流动性不足,滑点可能较大,资金量太小,可能不能达到10-20只持仓,来分散风险,10-100w可能是比较理想的,后续可以根据波动率动态调仓,或波动率大于一定值时触发再平衡加入ROE或其他财务指标,或者研发投入强度大的专精特新企业,进行组合优化。 阅读详情

相关推荐

GraphRAG + Ollama 本地化部署实战:从零搭建知识图谱问答系统

本文详细介绍了如何在本地部署GraphRAG与Ollama,搭建一个完全自主可控的知识图谱问答系统。通过逐步指导环境配置、项目初始化、核心设置修改以及源码适配,成功将GraphRAG从依赖云端OpenAI API转向本地Ollama服务,并选用qwen2.5:7b和nomic-embed-text模型。该方案有效解决了数据隐私与持续API成本问题,特别适合中小企业构建内部知识库或智能客服系统。

x2y3z4a5b的博客 918

【题解】【PAT甲】1118 Birds in Forest (25 分)(并查集)

题目链接 PTA | 程序设计类实验辅助教学平台 题目描述 Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of tree..

Elephant_King的博客 299

SRS(简单实时视频服务) 笔记(5)- 视频录制

在SRS使用中实现视频录制功能。

irainsa的博客 1698

【PAT_Python解】1118 如需挪车请致电

多学习其他大佬的AC代码!

新时代先锋的博客 404

MIC(Maximal Information Coefficient)最大互信息系数

MIC(Maximal Information Coefficient)最大互信息系数是一种用于衡量两个变量之间相关性的统计量。它扩展了传统的互信息(MI)和条件互信息(CMI)的概念,具有更广泛的应用范围。MIC能够捕获包括功能性和非功能性的广泛的关联,具有普遍性和公平性。普遍性意味着在足够的样本量下,MIC能够捕捉到广泛的相关关系,而不仅仅局限于特定的功能类型;公平性则意味着MIC对不同类型的包含同等噪声的关系给出了相似的分数。需要注意的是,虽然MIC具有很多优点,但它也有一些局限性。

qlkaicx的博客 4603

IC设计新手必看:如何正确使用去耦电容(decap)避免电源噪声?

本文深入探讨了IC设计中去耦电容(decap)的应用技巧,从核心原理到布局实现,帮助新手工程师有效抑制电源噪声。文章详细解析了MIM、MOM等电容类型的特性与选择策略,并提供了先进的布局技巧和验证方法,特别适用于28nm以下先进工艺的电路设计挑战。

weixin_30555125的博客 113

PAT 1118 C++ 版

PAT 1118 C++版 1.题意 给出每张图片中的鸟的数目,以及每只鸟的下标,求出树数。 同时查询两只鸟是否在同一棵树中。 2.分析 使用并查集 取鸟较小的索引的那个数作为那一组数据的根。 3. 测试用例 4 3 10 1 2 2 3 4 4 1 5 7 8 3 9 6 4 2 10 5 3 7 根据以上输入,得到的结果就是: 2 10 Yes no 4.代码 #include&lt;...

说文科技,做有态度的研究。 790

【七.三维视觉与视频分析】【1.点云处理:PointNet++/PointTransformer】

各位老铁,今天咱们要聊的可不是普通的二维图像处理,而是三维视觉领域最硬核的技术——点云处理。从最早的PointNet到如今的PointTransformer,这场技术进化堪比三维版的"像素革命"。今天咱们就深入解剖两大里程碑:PointNet++和PointTransformer,保证让你看完全文就能在点云领域横着走!想象一下,你抓了把沙子撒在空中,每粒沙子的位置都是三维坐标——这就是点云的典型形态。最后送大家一句话:点云处理就像在三维宇宙中寻找星辰的轨迹,既要望远镜的宏观视野,也要显微镜的细致入微。

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 473

PAT (Advanced Level) Practise 1118 Birds in Forest (25)

1118. Birds in Forest (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Some scientists took pictures of thousands

Occult 816

101、LLC谐振变换器的传递函数推导

文章摘要 LLC谐振变换器的传递函数推导是电源设计的关键环节。作者通过一次炸管事故案例,揭示了忽视传递函数计算的严重后果。LLC传递函数复杂的根源在于其三个谐振元件(Lr、Cr、Lm)的变频工作特性,导致增益曲线非单调变化。文章详细介绍了采用扩展描述函数法的建模思路,指出Lm对增益曲线的重要影响,并给出了传递函数的数学表达式及频率响应特性。通过实际调试案例,作者对比了错误补偿器设计(Type II)与优化方案(Type III)的效果差异,强调了实测验证的重要性。最后总结了5条实用经验,包括留足裕度、关注启

Jack010169的博客 152

【Unity】Gif图片播放插件(支持UI及模型纹理渲染两种模式)

unity本身不支持GIF格式文件直接渲染, 因此一般的做法是通过加载图片,通过代码控制其循环播放、停止等,模拟动画效果,本文简单介绍一下某个现有开源工具,感谢开源作者。

灵境引路人 4036

1118 Birds in Forest (并查集)

使用 并查集 得到每只小鸟的共同“父节点”

kiss_my_face的博客 346

嵌入式AI实战:基于RK3588部署YOLOv11并集成OpenCV实现实时推理(全流程详解)

本文详细介绍了在RK3588芯片上部署YOLOv11目标检测模型的全流程,包括环境搭建、模型转换和实时推理实现。主要内容为:1)通过YOLOv11官方工具将PyTorch模型转为ONNX格式;2)使用RKNN Toolkit2将ONNX模型转换为适配RK3588的RKNN格式;3)在RK3588上结合OpenCV实现实时视频推理功能。教程提供了完整的代码示例和详细步骤说明,帮助开发者快速在边缘设备上部署目标检测模型,实现AI视觉应用的落地。

LXY_LOVE36的博客 212

【PAT】1118. Birds in Forest (25)【并查集】

题目描述 Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the...

tjj1998的博客 314

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

1118 Birds in Forest (25分)【关于PAT中使用并查集的坑点】

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi...

爱写代码的坤坤的博客 294

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

【PAT】1118 Birds in Forest (25 分) - 并查集

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi...

mdjfk的博客 196

1118. Birds in Forest (25)-PAT甲级真题(并查集)

1118. Birds in Forest (25) Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the

柳婼 の blog 3358

PAT A1118 Birds in Forest (25 分)——并查集

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count...

weixin_30376453的博客 140

PAT A1118 Birds in Forest (25 分) 并查集

题目大意:给出N张照片,每张照片上有一些鸟的编号(<10^4),同一张照片上的鸟被认为属于同一棵树,求出最大有多少棵树和多少只鸟,并判断给出的两只鸟是否属于同一棵树。 常规并查集问题,如果不用路径压缩的话测试点3会超时。 AC代码: #include <vector> #include <cstdio> using namespace std...

HackingGate的博客 222

【PAT甲级】1118 Birds in Forest (25 分)【并查集】

1118 Birds in Forest (25 分) 思路 输入输出: 第一行为照片数量nnn,接下来nnn行,每行第一个数字是 kkk,后面是 kkk 个数字,表示该照片中的鸟的编号 鸟的个数最多是10410^4104,nnn的个数最多是10410^4104,kkk的个数最多是10 qqq个查询,qqq最大可达10410^4104 输出的第一行是最大可能的树的数量与鸟的数量,接下来n行每行输出Yes/No表示给定的两个数是否在同一个树上 具体实现: 首先需要一定的并查集的知识,具体实现可见htt

郭同学如是说 166

PAT甲级 1118 Birds in Forest (25分) 并查集/C++

1118 Birds in Forest (25分) 题目大意:给定n张照片,每张照片中有k只鸟在同一棵树上,再给出几对鸟,判断它们是否在同一棵树上。 典型的并查集问题!不懂可以看中国大学mooc上浙江大学的《数据结构》课程(在树(下),讲的很好,也有代码讲解和完整的代码实现) #include<iostream> //输入输出流头文件 #include<vector> //变长数组容器 using namesp

qq_43955154的博客 145

PAT(并查集)——1118. Birds in Forest (25)

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi...

WangXin Programmer 199

pat 甲级 并查集 A1118 Birds in Forest (25分)

1118 Birds in Forest (25分) Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in the f

weixin_42358356的博客 162

PAT甲级 1118 Birds in Forest (25分) 并查集

题目中规中矩,没有什么难度,标准的并查集就能拿下。 #include<iostream> #include<vector> using namespace std; int father[10010]; int findFather(int x) { int a = x; while (x != father[x]) { x = father[x]; } while (a != father[a]) { int z = a; father[a] = x; .

zs201609的博客 152

PAT A1118. Birds in Forest (25)(并查集)

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi

jolivan的博客 309

PAT - 甲级 - 1118. Birds in Forest (25) (并查集)

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi

i逆天耗子 744

PAT 1118. Birds in Forest (25) 并查集

1118. Birds in Forest (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Some scientists took pictures of thousands

yxpandjay的博客 249
上一篇: pat甲级 1020. Tree Traversals map递归建树 + BFS
下一篇: pat 1127. ZigZagging on a Tree (30) 递归建树 + BFS
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值