POJ 2524 - Ubiquitous Religions

Ubuntu虚拟机IP卡在127.0.0.1?别慌,试试这条万能命令 `sudo dhclient` 本文详细解析了Ubuntu虚拟机IP卡在127.0.0.1的常见原因及解决方案,重点介绍了`sudo dhclient`命令的使用方法及其变体,帮助用户快速恢复网络连接。同时提供了网络诊断工具和预防措施,适用于开发者和系统管理员应对网络故障。 阅读详情

Advanced Data Structures :: Disjoint Set


Description

有n个学生,编号从1~n。

学生们大都信仰着各自的神,各自的宗教。

当然也有不少同学有着相同的信仰。

那么,告诉你哪些同学有相同的信仰,

请求出有多少个神在同学们的心中。


Type

Advanced Data Structures :: Disjoint Set


Analysis

假设一个开头就有n个宗教,

然后用并查集并一下,

在并的时候检查是否原来就在同一个宗教,

否则每次合并都会少一个宗教。

并完之后,剩下的宗教数就是最后要求的宗教数了。


Solution

// POJ 2524
// Ubiquitous Religions
// by A Cod e Rabbit

#include <cstdio>

const int MAXN = 50002;

struct DisjointSet {
    int p[MAXN];
    int ans;
    void Init(int);
    void Make(int x) { p[x] = x; }
    int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); }
    int Union(int x, int y) {
        if (Find(x) != Find(y)) ans--;
        p[Find(x)] = Find(y);
    }
};

void DisjointSet::Init(int n) {
    for (int i = 1; i <= n; i++)
        Make(i);
    ans = n;
}

int n, m;
DisjointSet set;

int main() {
    int cnt_case = 0;
    while (scanf("%d%d", &n, &m) && (n || m)) {
        set.Init(n);
        for (int i = 0; i < m; i++) {
            int x, y;
            scanf("%d%d", &x, &y);
            set.Union(x, y);
        }
        printf("Case %d: %d\n", ++cnt_case, set.ans);
    }

    return 0;
}

100天精通Python(基础篇)——第1天:Python从起源到应用的全面解析(附上Python、PyCharm、VSCode下载安装详细教程) 阅读详情

相关推荐

深入Luckfox Pico的Web界面:从Angular前端到CGI后端的RV1106 IPCWeb全栈解析

本文深入解析了基于瑞芯微RV1106芯片的Luckfox Pico设备上,IPCWeb全栈解决方案的架构与部署。详细介绍了如何通过SDK编译配置,将现代Angular前端框架与高效的C++ CGI后端结合,并利用nginx和FastCGI在嵌入式环境中构建稳定、高性能的Web管理界面,为物联网设备开发提供了完整的实战参考。

3a9bq4r8t2y的博客 275

【并查集】POJ 2524 Ubiquitous Religions

POJ 2524 Ubiquitous Religions #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <string&gt...

L_X_ 206

傅里叶红外(FT-IR):Origin数据处理、光谱绘图、曲线优化、图形美化

双击 X 轴,选择“轴线和刻度线”,设置粗细为“2”(较常用的粗细度),主刻度和次刻度为“朝内”,然后在此对话框内选择左轴,设置粗细为“2”,主刻度和次刻度为“无”,上轴和右轴同左轴。(4)在第二个图层基础上新建第三个图层,针对第二组数据重复上述中(1)和(2)的操作,再添加第三组数据的折线图,并重复上述中(3)的操作。FTIR 光谱上的峰只有相对的强弱,因此只分析一个光谱上的一个峰的强度大小并无意义,一般分析两个光谱在同一位置的峰强相对大小,或者分析同一光谱不同位置的峰强相对大小并与另一光谱进行比较。

qiushireader的博客 3932

POJ 2524 Ubiquitous Religions

/*********************************** Problem: POJ 2524 Ubiquitous Religions Time: 266MS Memory: 352K Accepted Time: 2009-08-19 20:52:35 Tip: 并查集 http://hi.baidu.com/fandywang_jlu/blog/item/b49e40893...

万猫学社 1万+

让AI稳定生成流程图:基于Skill与Mermaid的工程化实践

流程图是软件工程中沟通业务逻辑的通用语言,但其绘制与维护却长期依赖手工工具,导致文档更新滞后、协作成本高。随着大语言模型技术的成熟,自然语言生成代码已成为可落地的技术路径,而Mermaid作为一款文本化图表语法,凭借其可版本管理、可自动渲染和可嵌入文档的优势,正逐步取代传统绘图工具。要让AI稳定输出合格的流程图,关键在于为模型定义一套清晰的Skill规则,约束输入结构、处理逻辑和输出格式。本文从流程图的工程痛点出发,介绍如何利用大模型将自然语言描述转化为结构化文本,再通过Mermaid CLI渲染成可视化图

weixin_42548782的博客 306

【故障处理】- ORA-01722

在执行升级脚本@?/rdbms/admin/catupgrd.sql时报错ora-01722。

weixin_39099660的博客 854

POJ 2524 Ubiquitous Religions 并查集

题意:现在在弄一个大学调查,调查的内容就是,大学生群体的信仰。 如果测试样例输入 1 2 就代表 1 2 拥有同样的信仰。 最后问你最多有多少个不同的 信仰。显然这是一个并查集的题目。而且是模版题目。传送门:POJ-2524-Ubiquitous Religions#include <stdio.h> int pre[50005]; int Find(int x) { int r=x;

知 识 不 是 装 饰。 348

【BLE系列-第六篇】GATT解析:属性、特征、描述符的逻辑关系

本文系统介绍了BLE协议中的ATT和GATT机制。ATT以"属性"为基本数据单元,包含UUID、Handle、权限和Value四个要素。GATT则在ATT基础上构建了服务、特征和描述符的层次结构:服务(UUID:0x2800/0x2801)通过声明属性标识,特征声明(UUID:0x2803)指向特征值(UUID:0x2Axx或自定义),描述符(UUID:0x2900~0x290F)提供附加信息。GATT复用ATT发现机制,通过定义特定UUID语义实现服务发现和特征管理。这种设计使BLE设

qq_43399763的博客 1929

POJ-2524 Ubiquitous Religions

POJ-2524 Ubiquitous Religions 题目链接:POJ-2524 题目大意:给定一对学生编号 即为这两个学生信奉同一份Religions 求一共有多少种Religions 解题思路:并查集 查出一共有多少种结果 完全的模板题 不会请移步并查集详解 代码块: #include<iostream> #include<algorithm> #include...

鱼头的水题之路 232

黑猫带你学UFS协议第13篇:UFS初始化详解(Boot Operation)

本文详细解析了UFS设备的初始化过程,包括部分初始化、加载启动代码(可选)和初始化完成三个阶段。重点介绍了如何通过设备描述符和逻辑单元描述符配置引导特性,以及如何从UFS设备加载启动代码。内容适用于嵌入式硬件和存储领域的开发者。

黑猫奥利奥的博客 3555

【OpenClaw】Edict 三省六部制部署与启动

文章摘要 本文聚焦Edict系统的本地部署与启动,提供三种安装方式:Docker快速体验、macOS/Linux原生安装和Windows生产仿真。核心目标是让用户能够独立完成系统启动和基础问题排查,确保看板、后端服务、同步脚本和网关正常运行。文章强调环境检查的重要性,并给出具体验收标准:浏览器能访问看板页面(http://127.0.0.1:7891)和接口返回JSON数据。同时提供一键启动/停止脚本和常见问题处理建议,帮助用户快速验证部署结果。配套系列教程涵盖部署启动、使用实战、二次开发和封装版本使用等内

Mr数据杨 2901

poj 2524 Ubiquitous Religions

poj 2524 Ubiquitous Religions Ubiquitous Religions Time Limit:5000MS Memory Limit:65536K Total Submissions:23262 Accepted:11464 Desc...

weixin_30907523的博客 117

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

poj 2524 Ubiquitous Religions(并查集)

题目链接:poj 2524 Ubiquitous Religions 题目大意:

不慌不忙、不急不躁 846

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

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

POJ2524 Ubiquitous Religions —— 并查集

题目链接:http://poj.org/problem?id=2524 题解: 找出最多能有多少个不同的宗教,直接并查集就可以了。 第一次提交时没有注意到要输出“Case %d :”, 以后要注意了,细心读题。 代码如下: #include//B - Ubiquitous Religions POJ - 2524 纯并查集 #include #include #inc

A man can be destroyed, but not defeated. 454

Ubiquitous Religions POJ2524

Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15791   Accepted: 7606 Description There are so many different religions in the worl

天堂人间 3335

【POJ2524】Ubiquitous Religions

**Description** 当今世界有很多不同的宗教,很难通晓他们。你有兴趣找出在你的大学里有多少种不同的宗教信仰。 你知道在你的大学里有n个学生(0 < n <= 50000) 。你无法询问每个学生的宗教信仰。此外,许多学生不想说出他们的信仰。避免这些问题的一个方法是问m(0 <= m <= n(n - 1)/ 2)对学生, 问他们是否信仰相同的宗教( 例如他们可能知道他们两个是否去了相同

远方 317

poj-2524 Ubiquitous Religions

Description There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your un

心の コード 388

poj 2524 Ubiquitous Religions

http://poj.org/problem?id=2524 跟hdu-1213 一样,首先有n个人,然后有m个关系,问属于不同关系的人有多少个。 #include int id[50001],sz[50001],n,m; int find(int p) { while(p!=id[p]) { // 路径压缩,会破坏掉当前节点的父节点的尺寸信息,因为压缩后,当前节点的父节

有一种力量叫乐观 618

Ubiquitous Religions POJ - 2524 并查集

Ubiquitous Religions POJ - 2524 并查集 #include<iostream> #include<algorithm> #define fori for(i=0;i<n;i++) #define fori1 for(i=1;i<=n;i++) #define ll long long const ll mod = 1e9 + 7; ...

ch_huibw的博客 189

POJ 2524-Ubiquitous Religions 并查集

题目来源:http://acm.pku.edu.cn/JudgeOnline/problem?id=2524解题报告:简单的并查集的应用吧#include using namespace std; typedef struct _node { _node* parent; int rank; }node; node **s; void makeSet(int x) { s[x]=new node; s[x]->rank=0; s[x]->parent=s[x]

kindlucy的专栏 786

poj2524 Ubiquitous Religions

照例先上题目 8:宗教信仰 查看提交统计提问 总时间限制: 5000ms 内存限制: 65536kB 描述 世界上有许多宗教,你感兴趣的是你学校里的同学信仰多少种宗教。 你的学校有n名学生(0 输入输入包括多组数据。 每组数据的第一行包括n和m,0 输出对于每组数据,先输出它的编号(从1开始),接着输出学生信仰的

null 1275
上一篇: POJ 1611 - The Suspects
下一篇: POJ 2236 - Wireless Network
Ra_WinDing
博客等级 码龄15年 50粉丝 125原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值