HDU1856 - More is better 利用并查集找最大群体数目

关于三维全波电磁场仿真软件CST的安装和问题解决 百度网盘链接:https://pan.baidu.com/s/1RgWr8Qau1EzSOlh29SewFQ提取码:fzza这里是2023版本的CST,需要其他版本的uu们可以去官网或者其他人的网盘下载。 阅读详情

HDU1856 - More is better: http://acm.hdu.edu.cn/showproblem.php?pid=1856

题意: a和b认识,b和c认识,则a b c互相认识. 给出一些相互认识的两个人的编号. 判断最多有多少人互相认识(包括自己).

代码: 

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN = 100011;
int N;
int x,y;
int MaxId,MaxNum,Num[MAXN],Father[MAXN];
void Initial()
{
	MaxId = MaxNum = -1;
	for(int i = 0;i < MAXN;i++)
		Father[i] = i,Num[i] = 1;//Num数组的元素都初始化为 1,最少有一个人 
}
int Find(int x)
{
/*	if(x != Father[x])
		Father[x] = Find(Father[x]);
	return Father[x];
*/
	return x == Father[x] ? Father[x] : Father[x] = Find(Father[x]);
}
void Union(int x,int y)
{
	x = Find(x);
	y = Find(y);
	if(x != y)
		Father[x] = y,Num[y] += Num[x];//合并的同时将人数加到根节点上,这里要注意,不要写反了 
}
int main()
{
	while(~scanf("%d",&N))
	{
		if(!N)
		{
			printf("1\n");
			continue;
		}
		Initial();
		while(N--)
		{
			scanf("%d%d",&x,&y);
			//这里求出出现过的id最大为MaxId,因为这里是千万的数量级,全部循环一次会耗费较多的时间 
			if(MaxId < x)MaxId = x;
			if(MaxId < y)MaxId = y;
			Union(x,y);
		}
		for(int i = 0;i <= MaxId;i++)//找出最大的人数
			if(MaxNum < Num[i])
				MaxNum = Num[i];
		printf("%d\n",MaxNum);
	}
	return 0;
}


《驾驭你的AI同事:WorkBuddy深度精通》027:11.1 私有知识库接入 本文详解WorkBuddy中私有知识库接入的RAG实现路径,聚焦“解析→切分→向量化→入库”四步流水线。强调知识源质量决定RAG上限:优先使用Markdown等结构化文档,扫描件需先OCR;切分采用递归字符+重叠(overlap)防语义断裂;向量化统一模型并附带元数据以支持溯源与权限控制;最终选择Pinecone、Weaviate或内置方案存入向量库。核心目标是让AI“基于资料说话”,杜绝“凭空编造”。 阅读详情

相关推荐

【阿里云大模型高级工程师ACP习题集】2.3 优化提示词改善答疑机器人回答质量

【摘要】这是我精心整理出对应的习题集,里面足足有 30 道题目,从基础概念到深度拓展,全方位覆盖章节重点、难点。不管你是想检验自己的学习成果,还是想针对薄弱环节进行强化训练,它都能完美适配!

davidkorhenn的博客 1641

并查集()

讲课三连 讲课1 讲课2讲课3 由于水平有限,并不能将并查集讲的透透彻彻,只是自己的一点见解,在做题目中看到的, 自己整理一下。个人觉得并查集有很多种,比如普通并查集,带权并查集,种类并查集,目前我只是见到过这三种(由于水平有限)。今天只是说说最普通不过的并查集。 先推荐个博客(风趣的讲解,但我感觉我还是没有理解并查集的本质)(还是我太菜了)。武侠版并查集 写的不错,大家可以看看,试着...

博客 1032

什么是以太网链路聚合

以太网链路聚合技术通过将多个物理端口捆绑成逻辑端口,可显著提升网络性能。该技术能增加总带宽(各链路带宽之和)、提高可靠性(故障秒级切换)并实现智能负载分担。主要分为手工模式和基于LACP协议的动态模式,后者能检测链路故障更可靠。配置时需确保接口参数一致、模式匹配,适用于核心交换、服务器接入等场景。华为设备通过创建Eth-Trunk接口、指定LACP模式并添加成员接口即可完成部署。这项成熟技术能以低成本解决带宽瓶颈和可靠性问题,是构建高速稳定网络的关键方案。

lai_2020的博客 681

并查集最详细总结(入门到精通)

并查集 给定N个元素,它们之间存在某种关系,对于这种关系的元素可以归结为一个集合,当数量太大的时候,查询等操作可能需要特别长的时间,并查集正是解决这种问题。 初始化F[x] 全部赋值为-1,F[x]=-1说明x为根结点。但在合并的时候不能判断find(x)==find(y)两个根节点都可以都是-1。 全部赋值为x,F[x]=x说明每个元素的父节点都是自己本身,比较符合逻辑,在合并的时候可以判断f...

qq_36206070的博客 1485

OTN传送网实战指南:从光层到电层的完整架构解析(附配置示例)

本文深入解析OTN传送网从光层到电层的完整架构,涵盖关键组件、技术实现及配置示例。通过高速公路与光传送网的类比,详细介绍了光层超宽传输管道构建、电层业务调度核心引擎以及控制平面智能运维实战。附有典型组网方案与故障排查指南,助力网络工程师高效部署与维护OTN传送网。

tomato的博客 692

【GlobalMapper精品教程】072:GlobalmapperV25中文版下载地址及安装教程

GlobalmapperV25中文版下载地址及安装教程安装包位于专栏完整数据包中,请订阅后从CSDN私信查收!最新GlobalMapper中文版入门实战实验教程,图文并茂,实用性强,内容包括:GM基础操作、数据处理及地形图制作、航测内业数据处理、点云处理、地形分析、空间分析、数据库建库入库等。配套完整案例数据,持续同步更新!订阅专栏后,从私信查收中文安装包永久版(中文23.0+24.0)及配套实验数据包。

智慧空间实验室 4751

并查集-认识的人

被字节跳动的题目难住了,感到了自己认识的差距。希望可以通过博客记录自己学到的算法或者方式吧,鼓励自己。  Bytedance Efficiency Engineering团队在8月20日搬入了学清嘉创大厦,为庆祝团队的乔迁之喜,字节君决定邀请整个EE团队,举办一个大型团建游戏-字节跳动大闯关。可是遇到了一个问题: EE团队共有n个人,大家都比较害羞,不善于与陌生人交流。这n个人每个人都向字节...

Mr.Lin的博客 849

HFSS实战项目——高带外抑制特性SIW带通滤波器

本文对单级滤波器和双级滤波器的设计、工作原理及仿真结果进行了详细分析,并验证了双级SIW带通滤波器在性能方面的优越性,为微波通信系统中滤波器的设计和应用提供了重要参考。

2401_87464239的博客 1821

并查集(合并与查找的集合)

https://www.cnblogs.com/xzxl/p/7226557.html (1)合并集合与路径压缩(方便查找根节点,节省时间和空间) pre[]一维数组是寻找前一个节点的数组(查询两个节点之间关系最快方法是并查集) pre[x]=find(pre[x]) (2)进阶(带权并查集,可以推算关系的集合) ...

while_black的博客 2025

uniApp微信小程序:利用live-pusher人脸活体检测功能+完整示例代码,uniapp使用live-pusher直播推流组件实现人脸验证-活体检测,检测人脸中的动作包括眨眼、张嘴、左右摇头动作

UniApp 使用 live-pusher 实现人脸活体检测(附完整源码)uniapp开发微信小程序人脸检测活体检测,在uni-app的微信小程序项目中使用live-pusher实现人脸识别,uniapp使用live-pusher实现模拟人脸识别效果,张张嘴、眨眨眼、向左摇头、向右摇头等动作,免费使用人脸活体检测的插件方案,uniapp小程序怎么免费使用人脸活体,直播推流,UNIAPP微信小程序使用live-pusher实现人脸识别(拍照)功能,在uni-app项目中实现人脸识别,既使用uni-app中的l

✅ 精选推荐文章 3021

路径规划 | 图解RRT*算法(附ROS C++/Python/Matlab仿真)

RRT*算法针对传统RRT算法进行了渐进最优改进,在添加节点到搜索树的过程中进行重连选择。本文图解RRT*算法原理,并采用ROS C++、Python、Matlab三种语言实现算法,加深理解

FRIGIDWINTER的博客 9412

POJ1611 The Suspects (求x所在集合的大小)

题目链接 http://poj.org/problem?id=1611 题目 警察抓贩毒集团。有不同类型的犯罪集团,人员可能重复,集团内的人会相互接触。现在警察在其中一人(0号)身上搜出毒品,认为与这个人直接接触或通过其他人有间接接触的人都是嫌疑犯。问包括0号犯人共有多少嫌疑犯? Input 多样例输入。 每个测试用例以两个整数n和m开头,其中n为人数,m为犯罪集团数。你可以假定0 &...

EnjoyingAC的博客 324

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

hdu1856More is better 并查集基础

More is better<br />Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others)<br />Total Submission(s): 2618    Accepted Submission(s): 1006<br /><br />Problem DescriptionMr Wang wants some boys to help him with a project. Becau

独行闹市无人问,青灯剑影响素琴 799

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【1】【并查集】HDU1856 More is better

图论初级

实现不可能 246

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

HDU 1856--More is better【并查集】

More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 18597    Accepted Submission(s): 6842 Problem Description Mr Wang want

_阿阿阿阿欢 472

【并查集】hdu 1856 More is better

并查集的简单变形

Gzbgreat的博客 335

HDU 1856 More is better(并查集)

More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 25387    Accepted Submission(s): 9107 Problem Description Mr Wang want

In my way 483

HDU - 1856 - More is better

HDU - 1856 - More is better Time Limit: 5000/1000 MS (Java/Others)     Memory Limit: 327680/102400 K (Java/Others) Problem DescriptionMr Wang wants some boys to help him with a project. Because th

在努力! 641

HDU Problem 1856 More is better 【并查集】

More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 24063    Accepted Submission(s): 8654 Problem Description Mr Wang

博客已搬迁到http://www.cnblogs.com/cniwoq/ 240

HDU 1856 More is better

More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 18728    Accepted Submission(s): 6880 Problem Description Mr Wang wa

dxx_111的博客 379

hdu 1856 More is better 并查集

More is better                                                                    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Problem Description Mr

LYHVOYAGE的专栏 6552

HDU 1856More is better(并查集)

Description Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements. Mr Wan

菜鸟的自我修养 259

hdoj 1856 more is better (如何记录节点数)

题目                :http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 191

张小V 455

【HD 1856】More is better

More is betterTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 24381 Accepted Submission(s): 8753Problem Description Mr Wang wants some bo

Nodies 538

hdu 1856 More is better

题意:

happy_lcj 615

hdu 1856 More is better (并查集)

问题描述: Problem Description Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirement

ww的博客 223
上一篇: HDU1829 - A Bug's Life 分组并查集
下一篇: HDU2473 - Junk-Mail Filter 利用虚拟数组实现删除并查集的节点
P_rogrammer
博客等级 码龄12年 0粉丝 26原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值