[bzoj3296][并查集]Learning Languages

LPDDR4协议规范之 (四)命令和时序 LPDDR4协议规范之 (四)命令和时序命令真值表激活操作读写访问操作读前沿和后沿突发读取操作流程读操作时序写前沿和后沿突发写操作写入均衡(待更新) 命令真值表 激活操作 ACTIVATE命令由两个连续命令组成,Activate-1命令和Activate-2。通过在(Activate-1)时钟的第一个上升沿保持CS HIGH,CA0 HIGH和CA1 LOW来发出Activate-1命令,通过... 阅读详情

Description

农夫约翰的N(2 <= N<=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1<= M <=30,000)种语言,编号从1
.. M.,第i头,会说K_i(1 <= K_i<= M)种语言,即L_i1, L_i2,…, L_{iK_i} (1 <= L_ij
<= M)。 FJ的奶牛 不太聪明,所以K_i的总和至多为100,000。两头牛,不能直接交流,除非它们都会讲某一门语言。然而,没有共同
语言的奶牛们,可以让其它的牛给他们当翻译。换言之,牛A和B可以谈话,当且仅当存在一个序列奶牛T_1,T_2,
…,T_k,A和T_1都会说某一种语言,T_1和T_2也都会说某一种语言……,并且T_k和B会说某一种语言。农夫约翰
希望他的奶牛更加团结,所以他希望任意两头牛之间可以交流。他可以买书教他的奶牛任何语言。作为一个相当节
俭的农民,FJ想要购买最少的书籍,让所有他的奶牛互相可以说话。帮助他确定:*他必须购买的书籍的最低数量

Input

*第1行:两个用空格隔开的整数:N和M
*第2..N+1行:第i+1行描述的牛i的语言,K_i+1个空格隔开的整数: K_iL_i1 L_i2,…,L_I{K_i}。

Output

*第1行:一个整数,FJ最少需要购买的书籍数量

Sample Input

3 3

2 3 2

1 2

1 1

Sample Output

1

//给三号牛买第二本书即可

题解

日常刷水
把语言搞一下并查集,统计一下出现的连通块个数-1就是答案了

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int fa[31000];
int findfa(int x){return fa[x]!=x?fa[x]=findfa(fa[x]):fa[x];}
int n,m,K[11000];
bool v[31000];
int main()
{
    memset(v,false,sizeof(v));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)fa[i]=i;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&K[i]);int last=0;
        for(int j=1;j<=K[i];j++)
        {
            int x;scanf("%d",&x);v[x]=true;
            if(last==0){last=x;continue;}
            int p=findfa(last),q=findfa(x);
            if(p!=q)fa[p]=q;
        }
    }
    for(int i=1;i<=m;i++)fa[i]=findfa(i);
    int cnt=0;
    for(int i=1;i<=m;i++)if(fa[i]==i && v[i])cnt++;
    printf("%d\n",cnt-1);
    return 0;
}
R以及Rstudio超详细安装教程(包括安装过程中出现的问题) R安装及Rstudio安装,以及安装中出现的问题 阅读详情

相关推荐

i春秋第二届春秋欢乐赛 classical writeup

i春秋第二届春秋欢乐赛 classical writeup 第一步:题目给出的提示 根据题目我们可以了解这道题应该是一个古典密码的题目,但是古典密码太多了我们如何知道是什么? 看题目给出的附件是一个很长很长的乱序字符串,我们可以想到用词频分析一下: 发现里面有一段不一样的信息:LyjtL3fvnSRlo2xvKIjrK2ximSHkJ3ZhJ2Hto3x9 像是base64解码能够做出来,但是发现...

hanjinrui15的博客 1429

bzoj3296: [USACO2011 Open] Learning Languages(并查集)

题目传送门 。 解法: 并查集。 一头牛连向他能说的语言。 然后可以通过翻译的话就相当于双向边咯。 意思就是牛可以去找语言,语言也可以找牛。 最后记录有多少个不同的集合-1即可 代码实现: #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;cstdlib&gt; #include&lt;iostream&gt...

Hanks_o的博客 446

Halcon实战:5分钟搞定金属表面划痕检测(附完整代码解析)

本文提供了一份基于Halcon的金属表面划痕检测实战指南。通过核心的动态阈值算法,快速从图像中提取局部对比度异常区域,并结合形态学后处理与特征筛选,精准识别划痕。文章详解了从代码搭建、参数优化到工业场景适配的全流程,帮助工程师在五分钟内构建稳定高效的机器视觉检测方案。

weixin_29084231的博客 496

BZOJ 3296: [USACO2011 Open] Learning Languages【并查集】

last[x]last[x]last[x]表示xxx这门语言上一个掌握的奶牛。 然后合并。 答案就是最后的集合个数-1。 #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #define db dou...

Yucohny 441

基于Matlab与Gurobi的园区微电网风光储协同规划:从独立运营到联合优化的建模实战

本文详细介绍了如何利用Matlab与Gurobi进行园区微电网的风光储协同规划建模实战。通过构建从独立运营到联合优化的数学模型,结合Yalmip工具箱,旨在解决源荷不匹配问题,实现储能系统的最优配置与运行,从而降低总供电成本并提升新能源利用率。

weixin_29053073的博客 140

EfficientNet中的MBConv模块详解:为什么它能如此高效?

本文深度解析了EfficientNet中的MBConv模块,详细介绍了其核心设计理念、效率优化技术和复合缩放理论。MBConv通过深度可分离卷积、倒残差结构和注意力机制三大关键技术,实现了计算效率与模型性能的平衡,成为高效网络结构设计的典范。

tcp8optimizer的博客 349

bzoj 3296: [USACO2011 Open] Learning Languages(并查集)

3296: [USACO2011 Open] Learning Languages Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 195  Solved: 102 [Submit][Status][Discuss] Description 农夫约翰的N(2 两头牛,不能直接交流,除非它们都会讲某一门语言。然而,没有共同语言的奶

clover_hxy的博客 746

区块链入门:用账本、乐高和三台旧电脑讲懂分布式账本

区块链是一种去中心化的分布式账本技术,其核心原理是通过密码学哈希、共识机制和链式结构实现数据不可篡改与多方共同验证。它不依赖单一中心,而是将交易记录同步复制到多个节点,依靠数学规则而非人工信任达成一致,从而在数字世界构建可验证的信用基础设施。这种‘集体见证’模式显著提升了系统抗单点故障与人为干预的能力,广泛应用于供应链溯源、数字身份、教育管理及公益透明等需强信任保障的场景。本文以账本类比、乐高拆解和Ganache实操为线索,面向零基础读者通俗解析哈希值、挖矿与智能合约等关键概念。

weixin_30517215的博客 274

Learning Languages——并查集经典问题洛谷P3026

一道经典的并查集应用题目。文章主要提供了如何使用并查集的前提条件以及AC代码

m0_52325450的博客 280

052、联发科Imagiq HyperEngine架构适配:天玑9000/9200的ISP多核并行调度与Tuning Toolkit调优案例

摘要: 项目组在适配联发科天玑9200的Imagiq 890 ISP架构时,遇到多摄预览功耗过高、帧率不稳等问题。通过分析多核调度机制,调整辅核QoS通道、优化AI-ISP协同模式(采用FREERUN+运动补偿),并利用Tuning Toolkit的Pipeline Viewer动态分配负载,最终降低功耗30mA、提升画质。关键经验包括:避免多核带宽冲突、合理配置动态时钟策略,以及统一校准参数版本管理。天玑9000/9200的HyperEngine架构需优先理解多核协同逻辑,再针对性调优,否则易引发场景兼容

zzfmlxs的博客 36

YOLOv11改进 | 注意力篇 | YOLOv11引入CBAM注意力机制

我们的实验表明各种模型的分类和检测性能得到了一致的改进,证明了 CBAM 的广泛适用性。简单介绍:CBAM的主要思想是通过关注重要的特征并抑制不必要的特征来增强网络的表示能力。模块首先应用通道注意力,关注"重要的"特征,然后应用空间注意力,关注这些特征的"重要位置"。到此本文的正式分享内容就结束了,在这里给大家推荐我的YOLOv11改进有效涨点专栏,本专栏目前为新开的,后期我会根据各种前沿顶会进行论文复现,也会对一些老的改进机制进行补充,如果大家觉得本文帮助到你了,订阅本专栏,关注后续更多的更新~

tsg6698的博客 2万+

BZOJ 3296: [USACO2011 Open] Learning Languages

Time Limit: 5 Sec Memory Limit: 128 MB Submit: 387 Solved: 206 [Submit][Status][Discuss] Description 农夫约翰的N(2 <= N<=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1<= M <=30,0...

weixin_30824479的博客 150

开源项目-智能算法中台管理系统

智能算法中台管理系统,系统主要有样本中心,算法中心,模型中心等模块

u010479989的博客 2998

BZOJ 3296 [USACO2011 Open] Learning Languages:并查集

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3296 题意:   农夫约翰的N(2 <= N <= 10,000)头奶牛,编号为1...N。   一共会流利地使用M(1<= M <=30,000)种语言,编号从1...M。   第i头,会说K_i(1 <= K_i <= M)种语言,...

a1392136的博客 142

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

【bzoj 3296】 Learning Languages 【USACO2011 Open】

Description 农夫约翰的N(2 &lt;= N&lt;=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1&lt;= M &lt;=30,000)种语言,编号从1  .. M.,第i头,会说K_i(1 &lt;= K_i&lt;= M)种语言,即L_i1, L_i2,..., L_{iK_i} (1 &lt;= L_ij &lt;= M)。 FJ的奶牛 不太聪明,所以K...

TLECODE的博客 378

深度学习工具包 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")

bzoj3296[USACO2011 Open] Learning Languages*

bzoj3296[USACO2011 Open] Learning Languages 题意: n头奶牛,每头牛会一些语言,总共有m种语言。求需让某些奶牛学会的最小语言数使得任意两只奶牛直接或间接可以用同种语言聊天(比如a会语言1,b会语言1和2,c会语言2和3,d会语言3则他们两两可以交流)。n≤10000,m≤30000。 题解: 如果一头奶牛会某种语言,则将这头奶牛与这种语言连边,最...

weixin_34144848的博客 68

bzoj 3296: [USACO2011 Open] Learning Languages

简述题意: 农夫约翰的N(2&lt;=N&lt;=10,000)只奶牛标号为1..N,同样的有M(1&lt;=M&lt;=30,000)种牛语标号为1..M,第i只奶牛会说K_i(1&lt;=K_i&lt;=M)种牛语,分别为L_i1,L_i2,…,L_{iK_i}(1&lt;=L_ij&lt;=M),农夫的奶牛不是特别聪明,所以K_i的累加和不大于100,000。 两只奶牛只有当他们至少有一...

01232012的博客 301

BZOJ3296: [USACO2011 Open] Learning Languages

【传送门:BZOJ3296】 简要题意:   给出n头牛,共有m种语言,每头牛会ki种语言,会相同语言的牛可以交流,A牛和B牛可以交流当且仅当它们能够通过和其他牛交流来互相交流   但是有些牛仍然不能互相交流,所以可以让某些牛学习一种或多种语言,让牛学习一种语言就必须买这个语言的书   求出能使得所有牛能相互交流的最少的书本数 题解:   并查集大水题,把有共同语言的牛放在一起...

weixin_30371469的博客 125

BZOJ——3296: [USACO2011 Open] Learning Languages

http://www.lydsy.com/JudgeOnline/problem.php?id=3296 Time Limit:5 SecMemory Limit:128 MBSubmit:254Solved:134[Submit][Status][Discuss] Description 农夫约翰的N(2 <= N<=10,000)头奶牛,编号为1...

weixin_30457065的博客 68

bzoj3296: [USACO2011 Open] Learning Languages

shui #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; int fa[11000]; int ...

weixin_30951743的博客 98

【BZOJ】3296: [USACO2011 Open] Learning Languages(tarjan)

http://www.lydsy.com/JudgeOnline/problem.php?id=3296 显然,每群能交流的群是个强联通块 然后求出scc的数量,答案就是scc-1 #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;cmath&gt; #include &lt;string&gt; #inc...

weixin_34390996的博客 78

[Codeforces] 277A - Learning Languages

题意: n个职员会门语言,

Freeway的博客 1330

ACM Learning Languages

DescriptionThe “BerCorp” company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each

会编程的起司猫 536

[USACO2011 Open] Learning Languages

[USACO2011 Open] Learning Languages Description 农夫约翰的N(2 &lt;= N&lt;=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1&lt;= M &lt;=30,000)种语言,编号从1 .. M.,第i头,会说K_i(1 &lt;= K_i&lt;= M)种语言,即L_i1, L_i2,..., L_{iK_i} (1 ...

MoonAndSea_zyyh的博客 345

codeforce C. Learning Languages(并查集)

题目链接:点击打开链接 The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers

Vision 692
上一篇: [bzoj4956][最短路][Floyd]Secret Chamber at Mount Rushmore
下一篇: [bzoj4887][矩阵乘法]可乐
Rose_max
博客等级 码龄10年 97粉丝 610原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值