HDU-1829 A Bug's Life(并查集)

渗透测试实战—云渗透(AK/SK泄露) 渗透测试实战思路分享:getshell方法及横向移动方法,云安全(AK/SK泄露) 阅读详情

题目链接:点击打开链接

题意:昆虫有两种性别:雌性和雄性,给出m对昆虫的编号,表示每对昆虫是异性关系,问是否存在矛盾,即可能有一对是同性关系

分析:可以将同性关系的昆虫合并入并查集,当某对昆虫的根结点相等(即是同性关系)时,这时存在矛盾, 如果所有对昆虫的根结点都不相同(即表示所有对昆虫都是异性关系),这时不存在矛盾。因为输入的每一对昆虫事先被确定为异性关系,所以可以用数组sex[i]表示和i异性的昆虫,那么,对于一对昆虫a和b,和a同性的是sex[b],和b同性的是sex[a],于是每次merge(sex[a],b)和merge(sex[b],a)  

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=2005;
int pre[maxn]; //存储同性的信息,pre[i]表示i的父结点
int sex[maxn];//存储异性的信息,sex[i]表示i的异性
int n,m;
void init()
{
    for(int i=1;i<=n;i++)
        pre[i]=i;
}
int root(int x)
{
    return pre[x]==x?x:pre[x]=root(pre[x]);
}
void merge(int x,int y) //合并x和y
{
    if(root(x)!=root(y))   //去重条件,如果x和y都在并查集中就不用再次合并了
    {
        pre[root(x)]=root(y);
    }
}

int main()
{
    int T;
    cin>>T;
    int cnt=1;
    while(T--)
    {
        scanf("%d%d",&n,&m);
        init();
        memset(sex,0,sizeof sex);
        int a,b;
        bool flag=false;
        while(m--)
        {
            scanf("%d%d",&a,&b);
            if(root(a)==root(b)) { flag=true; continue; }
            if(sex[a]==0) //如果a之前没有发现和它异性的,就将a的异性置为b
                sex[a]=b;
            else merge(sex[a],b);//如果之前有与存在异性关系的昆虫sex[a],就将sex[a]和b合并
            if(sex[b]==0)
                sex[b]=a;
            else merge(sex[b],a);
        }
            printf("Scenario #%d:\n",cnt++);
        if(flag)
            puts("Suspicious bugs found!");
        else puts("No suspicious bugs found!");
        puts("");
    }
    return 0;
}


【RT-DETR涨点改进】全网独家创新、细节涨点改进篇 | AAAI 2025 | 将 CEM 颜色增强模块引入RT-DETR ,目标检测不再惧怕雾天和低光检测、小目标检测、遥感目标检测高效涨点 本文提出了一种新型结构引导去雾网络(SGDN),通过双色引导桥(BGB)和色彩增强模块(CEM)有效解决雾霾图像去雾问题。BGB利用YCbCr空间的纹理特征引导RGB特征恢复,CEM通过聚合YCbCr通道信息增强RGB色彩感知。实验证明该方法在真实雾霾数据集上优于现有技术,能同时保持色彩准确性和纹理清晰度。文章还提供了完整的代码实现和模型配置指南,包括三种改进版RT-DETR网络结构(rtdetr-l/r18/r50-CEM.yaml),为图像去雾和目标检测任务提供了实用解决方案。 阅读详情

相关推荐

三分钟解决RKNN-Toolkit2安装失败:从模块报错到成功验证的完整记录

本文详细记录了RKNN-Toolkit2安装失败的解决方案,从环境配置到模型转换实战,特别针对常见的'No module named 'rknn''报错提供了完整修复指南。通过YOLOv8模型转换示例,展示了从ONNX到RKNN格式的完整流程,并分享了在RK3588芯片上的部署优化技巧。

html8的博客 264

hdu-1829 & poj-2492 并查集

http://acm.hdu.edu.cn/showproblem.php?pid=1829 #include #include #include #include #include #include #include #include #include #include using namespace std; int t, n, m; int fa[2200]

mfcheer 845

cocos2dx中DrawNode画线锯齿和非凸多边形填充

记录一下在cocos2dx中使用DrawNode所遇到的2个问题 1.画线锯齿问题 ios版本下,在AppController.mm中设置CCEAGLView的multiSampling和numberOfSamples。如下图 CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]

hello-world 5414

HDU 1829 A Bug's Life(种类并查集)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Background

超级菜鸟ZiP的小窝 773

基于C#的跨平台上位机开发:一次编写,多平台运行

摘要: 本文探讨了如何利用C#进行跨平台上位机开发,以适配Windows、Linux、macOS等多平台需求。通过分析传统单平台开发的局限性(如API差异、硬件接口兼容性),提出基于.NET 5/6/7的解决方案,重点推荐Avalonia(类WPF的跨平台UI框架)和GtkSharp(基于GTK+)实现图形界面。同时,针对硬件通信需求,介绍了System.IO.Ports串口通信和LibUsbDotNet的跨平台支持,并强调多平台调试(VS Code、Docker)的重要性,最终实现一次编码、多端部署的高效

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1404

STC15单片机双串口通信实战:串口2配置与多设备交互

本文详细介绍了STC15单片机双串口通信的实战配置,重点解析串口2的硬件连接、寄存器设置及多设备交互实现。通过实际项目案例和完整代码示例,帮助开发者快速掌握STC15串口2的配置技巧,解决常见通信问题,提升嵌入式系统开发效率。

weixin_29174013的博客 255

HDU 1829 A Bug's Life (并查集+BFS(广度优先搜索))

A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6595 Accepted Submission(s): 2154 Problem Description Background Prof

公众号:ByteCode 1402

C++利用spdlog生成日志

C++利用spdlog生成日志下载编译spdlog配置并使用 环境:Win10-x64+VS2015 spdlog是一个快速的C++日志库,能够兼容C++11,具备快速、无需依赖第三方库、支持多线程、多平台的优良特性! 下载编译spdlog 1.第一步,下载spdlog 下载spdlog,下载地址:https://github.com/gabime/spdlog#header-only-version,从Github上下载zip压缩包。下载完成后会获取一个名为spdlog-1.x.zip的压缩包 2.第二步

weixin_42975610的博客 3217

HDU1829(带权并查)

#include&lt;cstdio&gt; #include&lt;iostream&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; using namespace std; const int maxn=2010; int fa[maxn]; int sex[maxn]; int n,m; int flag; void init()...

NicoleYWJ的博客 479

【机器学习入门】1.4 吃透这些基本术语,才算真正入门

本文通过"挑西瓜"的生活案例,形象解释了机器学习的基本术语。样本对应单个西瓜,特征如色泽、根蒂等是观察维度,特征值是其具体表现,标签是西瓜的好坏判断。数据集是样本集合,特征向量是样本的数学表达,特征空间是所有可能的样本组合。文章强调数据集需划分为训练集、验证集和测试集,以评估模型的泛化能力。最后整理了术语对照表,并解答了常见问题。这些基础概念是理解机器学习的关键,建议读者重点掌握。

国科大硕士在读,分享Python/GEE/Matlab/R专业代码实践,涵盖数据分析、算法开发与应用技巧等,以代码会友。 654

用Omniverse Kit开发第一个USD插件:从环境配置到实战案例(Python 3.7版)

本文详细介绍了如何使用NVIDIA Omniverse Kit和Python 3.7开发第一个USD插件,涵盖从环境配置到实战案例的全过程。通过创建可实时同步材质属性的USD插件,开发者可以快速掌握Omniverse开发框架,提升3D内容创作效率。

x8y9z0的博客 586

HDU - 1829 A Bug's LIfe 带权并查集

Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gend...

祈的博客 436

SAP UI5 OData V4 操作结果访问:从 getObject 到返回值上下文与 $$inheritExpandSelect

SAP UI5 OData V4 操作结果获取指南 摘要:在 SAP UI5 OData V4 模型中,操作结果需通过绑定上下文获取而非直接从 invoke() 返回。本文详解核心要点: 数据获取路径 使用 invoke() 发起请求后,通过 getBoundContext().getObject() 获取结果 特定场景下 invoke() 可能返回返回值上下文(如草稿切换) 关键实践技巧 使用 $$inheritExpandSelect 继承字段选择,避免二次读取 对象页应用中,通过替换绑定上下文实现无缝

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

HDU 1829A Bug's Life 并查集

A Bug's Life Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders...

xcatf的博客 584

Devexpress16.2.6破解工具

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

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

hdu 1829 A Bug's Life 并查集

hdu1829链接:点击打开链接 本想用vector写,没写出来/衰,看了一下结题报告,哎,我真的没学会并查集。利用并查集,当根节点相同的时候,观察两点与根节点的关系 是同性还不异性,重点是在查找根节点的时候就要更新各点与爷爷的关系 code: #include #include #include using namespace std; int n,m; int father[2100],

lois_123的专栏 429

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

HDU 1829 A Bug's Life (分组并查集)

题目意思:给定一系列数对,例如a和b,表示a和b不是同一种性别,然后不断的给出这样的数对,问有没有性别不对的情况。 例如给定: 1 2 3 4 1 3 那这里就是说1和2不是同种性别,3和4也不是同种性别,1和3不是同种性别,那这样就说明1和3是同一种性别,2和4是同一种性别,所以没有任何歧义,这时候输出No suspicious bugs found!。 但是例如,(本文作者:优快云:凌风) 1 2 2 3 1 3 1和2不同性别,2和3不同性别,那么

凌风 6783

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

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

HDU1829 A Bug's Life 并查集

并查集模板:http://blog.youkuaiyun.com/mishifangxiangdefeng/article/details/7165351/* HDU1829A Bug's Life 并查集的应用 这题不是判断是否在同一集合,而是判断是否在不同的集合 */ #include #include "UFS.h" using namespace std; int oppo[MAXN];//记录系

幸福在路上 1926

【并查集】hdu 1829 A Bug's Life

对这题还是一知半解。。代码先贴上,回头继续看。。

Gzbgreat的博客 483

HDU1829 - A Bug's Life 分组并查集

HDU1829 - A Bug's Life 分组并查集,和POJ上的"食物链"是同一类的题,这题是最基础的分组并查集.

P_rogrammer的专栏 697

HDU 1829 A Bug's Life 并查集

A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1025 Accepted Submission(s): 376   Problem Description

窦小雨的小点子 352

HDU 1829 A Bug's Life(种类并查集)

http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7294    Accepted Submission

fcbruce 1174

HDU 1829 A Bug's Life【种类并查集】

A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14050    Accepted Submission(s): 4572 Problem Description Background

AC_Dreameng 973

hdu 1829 A Bug's Life 并查集

基础的带权并查集,也是入门的种类并查集,具体做法参考poj 1182 食物链 #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define lson l, mid, rt <

uuuuuu 463

【种类并查集】 hdu1829 A bug's Life

A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15009    Accepted Submission(s): 4880 Problem Description Background

Hi_jiaxinwei的博客 367

HDU-1829.A Bug's Life(带权并查集)

A Bug’s Life Problem Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interac...

紫藤&code的博客 212

HDU 1829 A Bug's Life 并查集

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1829 代码如下: #include #include #include #include #include #include #include #include #include #include #include #include #include #i

lamborghini1993 1129
上一篇: codeforces-407B Long Path(dp)
下一篇: codeforces-385C Bear and Prime Numbers(素数筛选法+维护前缀和)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值