HDU1213基础并查集

Windows下构建ImGui.Net 工具 Visual Studio 2017 操作 下载项目 git clone https://github.com/mellinoe/ImGui.NET.git 编译 右键以下两个项目并调试: ImGui.NET.SampleProgram ImGui.NET.SampleProgram.XNA Error fix 中间遇到一些问题: SDK版本不对 去微软官网下载安装对应版本 由于设置了代理被远程服务器拒绝连接 关闭代理(也许在环境变量中) nuget源无对应资源,404 NOT FOUN 阅读详情

题意:
今天是Ignatius的生日,他邀请了许多朋友,现在他需要对这些朋友分桌,这些朋友只和认识的人坐在一起,例如A认识B,B认识C,则ABC可以在一桌,若A认识B,B认识C,D认识E,则ABC一桌,DE一桌。(Ignatius不考虑在内)

分析:
基础的并查集(关于什么是并查集可以查看这里:http://blog.youkuaiyun.com/link_ray/article/details/78067585),初始化所有个体为各自为单独的一个集合。
输入数据把属于同一集合的个体连通,最后剩余几个集合就说明需要多少张桌子。

#include <set>
#include <numeric>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <string>
#include <sstream>
#include <map>
#include <functional>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define REP(idx1,num1) for(int idx1=0;idx1<(num1);idx1++)
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define mem(s) memset(s,0,sizeof(s));
const double EPS = 1e-6;
const int maxn = 1000 + 10;
int p[maxn];
//查找根节点
int find(int x){
    while(p[x] != x){
        x = p[x];
    }
    return x;
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        mem(p);
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i = 0; i < n; ++i)
            p[i] = i;
        for(int i = 0; i < m; ++i){
            int a,b;
            scanf("%d%d",&a,&b);
            a -= 1;b -= 1; // 客人从0开始编号
            int x = find(a);//找到根
            int y = find(b);//找到根
            if(x != y){
                p[x] = y;//将两个独立集连通
                n--;//少一张桌子
            }
        }
        printf("%d\n",n);
    }
    return 0;
}
【论文详解】AlphaGenome——Sequence-to-Multimodal-Genome-Track **AlphaGenome** 是由 **Google DeepMind** 于 2025 年 6 月发布的突破性 AI 模型,专门用于预测非编码区遗传变异的功能效应。该模型采用受 **U-Net** 启发的卷积架构结合 **Transformer** 模块,创新性地解决了传统模型在输入序列长度与预测分辨率之间的核心矛盾——能够在 **1M 碱基对的超长上下文** 下实现 **单核苷酸分辨率** 的精准预测。 阅读详情

相关推荐

renderdoc的使用

renderdoc可以用来捕获帧渲染情况,排查一些GPU渲染、资源规格等问题。 下面讲述一些该软件连接真机调试使用。 一、下载安装renderdoc 软件的下载地址:https://renderdoc.org/可直接点击下载即可。该软件是开源免费的,不用破解。 下载后直接安装即可使用。 二、打开使用renderdoc 打开界面后,默认的界面布局如下图所示,(这里我已经设置了黑色主题,可以忽略这点),renderdo中主要的窗口有Texture Viewer(纹理查看器)、Event B.

x_xingduo_2315的博客 2万+

HDU-1213(简单DFS)

这道题目是一道简单的DFS,只需要用邻接表构出边之后,进行DFS, 一次DFS之后自加1,就可以 贴出代码: #include #include #include #include int N,M;//N represents the number of points,and M stands for the number of edges; int head[2000]; str

李硕 813

FOC时序及电流采样注意事项

摘要:本文介绍了无刷电机FOC(磁场定向控制)的实现方法,重点解析了电流采样时序与PWM同步的关键技术。在S32K144平台上,需使用两个独立的ADC组件实现双路电流同步采样,采样时刻必须严格对应低边MOS管开启时间并位于PWM波形中央。文章详细说明了硬件触发时序设计、采样电阻配置原则,并通过示波器实测波形验证了电流反馈电路的正确性,指出正弦电流波形应是理想输出形态。关键点包括ADC-PWM时序同步、低边MOS采样及正确的PWM映射配置。

qq_40916548的博客 2622

并查集 Table问题

并查集

fragle_spume的专栏 370

【C++PTA】6-1 Point类的运算 (10 分)

定义Point类,有坐标x,y两个私有成员变量;对Point类重载“+”(相加)、“-”(相减)和“==”(相等)运算符,实现对坐标的改变,要求用友元函数和成员函数两种方法实现。对Point类重载<<运算符,以使得代码 Point p; cout<<p<<endl;可以输出该点对象的坐标。 函数接口定义: 实现Point类。 裁判测试程序样例: /* 请在这里填写答案 */ int main(int argc, char const *argv[]) { P

libertye的博客 2367

解决Qt平台插件初始化失败:This application failed to start because no Qt platform plugin could be initialized

本文深入解析了Qt应用程序启动时常见的‘platform plugin’初始化失败报错,指出其核心在于环境变量冲突或多版本Qt共存导致的插件路径混乱。文章提供了从环境变量检查、路径调整到文件补全的完整解决方案,并给出了使用windeployqt工具等预防性开发实践,帮助用户和开发者彻底解决这一经典问题。

weixin_29229261的博客 2195

并查集

并差集的用途:在处理一个数列有多个两两相互关联的元素,将多个相互关联的放入一个集合,查找并输出有多少组集合。思路:用一个一维数组,将每个元素存入一个数组内。在通过元素,下标的联系构建一个集合。想法就是,如果n个人,每个人都有一个人编号1~N。第一: 将数组的下标和储存内容一致,就是用一个循环for(i=1;i&lt;=n;i++) s[i]=i;//这时的还没有输入有关系的元素,所以这个代表着每个...

woshi_momomo的博客 291

CGAL AlphaShape算法(自适应Alpha值,二维版本)

CGAL AlphaShape算法(自适应Alpha值,二维版本)

dayuhaitang1的博客 2324

(求连通分量的个数-基础并查集)hdu1213 How Many Tables

hdu1213 How Many Tables 基础并查集。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cmath&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; using namespace std; const int maxn=1010; int ...

269

VTK:vtkAssembly用法实战

VTK:vtkAssembly用法实战程序输出程序完整源代码 程序输出 程序完整源代码 #include <vtkActor.h> #include <vtkAssembly.h> #include <vtkAxesActor.h> #include <vtkCubeSource.h> #include <vtkNamedColors.h> #include <vtkNew.h> #include <vtkOrientation

希望我的博客,能帮上你解决学习中工作中所遇到的问题 936

可控异常的契约化设计:在 ABAP 中用 CX_STATIC_CHECK 把可预期错误变成接口的一部分

文章摘要: 本文探讨了ABAP系统中异常处理的工程化设计原则,强调将可预期的业务异常作为接口契约的一部分。核心观点是:对于调用方能够合理处理的错误情况,应使用继承自CX_STATIC_CHECK的受检异常,通过方法签名强制调用方处理或显式转发。文章对比了ABAP三大异常根类的适用场景,提出"三问法"判断异常是否适合受检处理,并给出了包含上下文信息的异常类实现示例。通过Fiori文件上传案例,展示了如何在分层架构中合理传递和转换异常,最终在OData服务层将业务异常映射为标准错误响应。这种

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

HDU 1213 How Many Tables【并查集基础】

HDU 1213 How Many Tables 原题链接:vjudge传送门 题目大意: 给定n个人,m组关系(两人之间),关系可以传递,问总最终共有几组关系 eg:若a和b有关系,b和c有关系,则a,b,c都有关系,且为同一组关系 具体思路: 并查集 具体代码: #include<iostream> #include<cstdio> #include<algori...

指弹键盘哼民谣 389

1、初探 Tiny Machine Learning

Tiny Machine Learning(TinyML)是机器学习与嵌入式系统的融合领域,致力于在资源受限的微控制器上运行AI模型。本文介绍了机器学习基础、TinyML的核心概念、应用领域(如智能家居、工业物联网、医疗保健)、面临的挑战(如资源限制、模型压缩、数据质量),以及从硬件准备到模型部署的实践步骤。通过利用训练与推理的资源不对称性,可在PC上训练模型并部署至低功耗设备进行实时推理,推动边缘智能的发展。

loss4bartender的博客 121

hdu1213——并查集基础题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have ...

mumei的博客 352

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

hdu 1213 基础并查集

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1213非常基础的并查集,先假设需要n张桌子,每次合并2个集合,就减少一张桌子。#include <cstdio> #include <iostream> #define maxn 100005 using namespace std; int fat[maxn],t,n,m,a,b; int find

博客 333

蓝牙模块HM-10手册

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

hdu1213How many tables 并查集基础

How Many TablesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3256    Accepted Submission(s): 1444Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ig

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

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

HDU1213 How Many Tables(基础并查集)

HDU1213 How Many Tables(基础并查集) 链接:题目Time Limit: 1000ms Memory Limit: 32768KB Description Today is Ignatius’ birthday. He invites a lot of friends. Now it’s dinner time. Ignatius wants to know how m

Minecode的博客 508

HDU1213 基础并查集

How Many Tables 问题描述 : Today is Ignatius’ birthday. He invites a lot of friends. Now it’s dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all

sinat_32172551的博客 185

HDU1213并查集基础

题意:给出总人数与数对两两间的“朋友”关系 将所有有朋友的人坐在一起 求所需要桌子的数量 题意抽象化:所有有关系的人相连成树 即m个合并操作后 求树的个数(根节点的个数)#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; i

qq_24770169的博客 356

HDU 1213 How Many Tables( 基础并查集)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213  题意:输出有多少个连通分量 分析:看大佬的博客有两种思路是实现,我的实现是假设将所有的点都视作一个连通分量,然后每次合并减一即可; 另一种思路:返回0就ans++;也行,大致思路开始一样的吧 #include&lt;cstdio&gt; #include&lt;iostream&...

Sean 195

hdu1213 - How Many Tables (基础并查集)

How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13487    Accepted Submission(s): 6616 Problem Description Today is Ig

ITCTO-疯男的优快云博客 603

HDU 1213 How Many Tables(并查集)

传送门:HDU 1213

一个写程序的 748

HDU 1213How Many Tables(基础并查集)

Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the frien

dlnumk的博客 271

hdu1213(基础并查集)

Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the fr...

时光、疏离了记忆づ童话的博客 588

hdu 1213 (基础并查集)

Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, a

爱梦者的心之旅 197

hdu1213 How Many Tables (基础并查集)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意: 首先输入一个数T为案例数,每一个案例的第一行输入一个N和一个M,N代表有多少个人(编号从1到N),M表示有几组人是朋友,随后的M行,表示谁和谁是朋友。注意朋友的朋友也互为朋友,只有朋友才能坐在同一个桌子,求需要的最少的桌子数。 代码: #include &lt;iostream...

行云出岫 185
上一篇: 51Nod1086背包问题V2(二进制优化)
下一篇: HDU1506(最大子矩阵)
Link_Ray
博客等级 码龄9年 44粉丝 156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值