PAT a1118

RuoYi项目适配达梦数据库(二) RuoYi项目,代码生成模块的达梦数据库适配。 阅读详情

目的:通过图片找树,找出有多少个鸟

输入:

N  图片数

K  每张图片上的鸟的个数

Q 查询数目

输出:

输出有几棵树,几只鸟

对查询判断两只鸟是否属于同一棵树。

#include<stdio.h>
#include<set>

using namespace std;

const int maxn = 10010;
int father[maxn];
int N;
set<int> tree;
bool exist[maxn] = {false};

void init()
{
    for(int i=1;i<maxn;i++)
    {
        father[i] = i;
    }
}
int findfather(int x)
{
    if(x==father[x]) return x;
    else
    {
        int F = findfather(father[x]);
        father[x] = F;
        return F;
    }
}
void Union(int a,int b)
{
    int fa = findfather(a);
    int fb = findfather(b);
    if(fa!=fb)
    {
        father[fa] = fb;
    }
}
int main()
{
    scanf("%d",&N);

    init();
    int cnt = 0;
    for(int i=0;i<N;i++)
    {
        int K,u,v;
        scanf("%d%d",&K,&u);
        if(exist[u]==false)
        {
            exist[u] = true;
            cnt++;
        }
        for(int j=1;j<K;j++)
        {
            scanf("%d",&v);
            if(exist[v]==false)
            {
                exist[v] = true;
                cnt++;
            }
            Union(u,v);
        }
    }
    for(int i=1;i<=cnt;i++)
    {
        if(exist[i]==true)
        {
            tree.insert(findfather(i));
        }
    }
    printf("%d %d\n",tree.size(),cnt);
    int Q;
    scanf("%d",&Q);
    for(int i=0;i<Q;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        if(findfather(u)==findfather(v))
        {
            printf("Yes\n");
        }else
        {
            printf("No\n");
        }
    }
    return 0;
}

反思:明显用并查集。并查集有写不熟练。还有要记住,若是没有结果,往往是因为循环出问题。比如数组越界,或者遍历方向反了。并查集要模板化,否则会出问题的。

Cocos2d-x手游逆向实战:Frida高阶Hook与动态解密技术 Cocos2d-x作为主流跨平台游戏引擎,其混合架构(C++核心+JNI桥接+Lua/JS脚本)和强加固策略(符号剥离、anti-frida、so加壳)使传统逆向方法失效。本文围绕‘无符号定位’‘C++函数硬编码地址识别’‘Lua层AST级劫持’‘OpenGL内存回溯解密’四大关键技术展开,深入解析如何在真实上线项目中稳定hook被strip的libcocos2d.so关键函数、绕过反调试心跳检测、从glTexImage2D参数逆向追踪明文资源,并结合熵值扫描实现零先验知识的内存明文发现。面向已掌握Frid 阅读详情

相关推荐

大话西游2经典单机版V8:一键架设+GM全功能+仙玉自由修改

本文详细介绍大话西游2经典单机版V8的一键架设教程和GM全功能使用指南,包括仙玉自由修改技巧。该版本无需虚拟机,解压即玩,完美还原官服经典玩法,支持离线运行,是老玩家重温经典和新玩家体验游戏的理想选择。

weixin_27303545的博客 1133

【题解】【PAT甲】1118 Birds in Forest (25 分)(并查集)

题目链接 PTA | 程序设计类实验辅助教学平台 题目描述 Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of tree..

Elephant_King的博客 299

川崎机器人 AS语言基础运动指令表

    功能简介 动作方式 参考坐标系 位置特性 X,Y,Z 角度特性 O,A,T 指令格式(距离单位毫米,时间单位秒,角度单位度 示例1 示例2 运 动 指 令 JMOVE 以关节移动到目标点 关节移动方式 基础坐标系 不受控 伪随机动作 JMOVE 目标点 JMOVE #yd JMOVE put1 LMOVE 以直线移动到目标点 直线移动方式

喜欢自学并分享经验的技术宅 9351

PAT A1118做题分析

我出错的地方: 试图把树给并起来。这里鸟有编号,正确做法应该是把鸟并起来。而不是树。 思路分析 用并查集的办法。 cnt[i]数组保存以i为FindFather结点的集合里面的鸟的个数, exist[i]表示鸟的id——i在输入的鸟的序号里面是否出现过, 遍历cnt数组并累加所有不为0的个数即可得知有多少棵树, 累加所有出现过的鸟的id的cnt的值即可得知鸟的个数 代码如下: for(i...

weixin_44980441的博客 334

C++幂运算全解析:std::pow()函数详解与实战指南

本文详细介绍了C++标准库中的std::pow()函数,包括其基本用法、数学定义和多种重载形式。重点分析了该函数在科学计算、图形处理等领域的实际应用,并提供了性能优化方案如快速幂算法和预计算表。文章还探讨了精度控制、错误处理等关键问题,最后通过一个完整计算器实现展示了综合应用。std::pow()作为基础数学函数,合理使用能显著提升计算效率和代码可靠性。

专注现代C++实战,从核心语法到高性能编程,助力开发者深入掌握系统级编程精髓。 340

第六:Charles抓包-苹果手机抓包

【代码】第六:Charles抓包-苹果手机抓包。

欢迎来到本博客! 1658

PAT甲级1118 Birds in Forest//并查集

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in the forest, and for any pair of b

冷眼看world的博客 219

飞牛fnNAS搭建web版微信

摘要:本文介绍了一种通过Docker在飞牛NAS上部署微信客户端的方法,实现24小时同步微信聊天记录。具体步骤包括:1)激活飞牛NAS的Docker功能并配置镜像加速源;2)创建专用文件夹并下载docker-wechat镜像;3)设置容器参数并部署微信客户端;4)通过局域网或ZeroTier内网穿透实现远程访问。相比传统Windows/Linux方案,该方法资源占用更低,适合需要长期保存微信聊天记录的用户。

dgnankai的专栏 3332

PAT (Advanced Level) Practise 1118 Birds in Forest (25)

1118. Birds in Forest (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Some scientists took pictures of thousands

Occult 817

Altium Designer系列: 软件系统参数配置保存

【Altium Designer实践】 软件系统参数配置保存 作者 CodeAllen ,转载请注明出处 目录设置中文菜单高亮模式设置文件关联pcb设置布线设置保存配置文件(复用) 设置中文菜单 DXP->Preferences 高亮模式设置 文件关联 pcb设置 布线设置 保存配置文件(复用) ......

CodeAllen嵌入式 2018

【AI智能体】Codex 基于Git 实现项目管理实战操作详解

Codex 基于Git 实现项目管理实战操作详解

congge 5455

PAT1118(并查集)

PAT1118 1118 Birds in Forest (25分) Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to he...

weixin_44572860的博客 296

WINCC7.3破解文件

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

第十四天PAT-A1118 Birds in Forest并查集

A1118 Description: 位于同一图片中的鸟为同一棵树,给出每张照片中鸟的编号,求总树的数目,并判断两只鸟是否位于同一棵树; 思路: 并查集,再次注意maxn 不是题目中的N<=1e4… #include<iostream> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<algorithm> #in

giggle66的博客 197

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

PAT A 1118. Birds in Forest

PAT A 1118. Birds in Forest (25) https://www.patest.cn/contests/pat-a-practise/1118 裸并查集#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> id, sz; int n, cnt; U

more time 392

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

PAT_A1118#Birds in Forest

Source: PAT A1118Birds in Forest(25分) Description: Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same ...

weixin_34378045的博客 141

PAT A1118

#include &lt;iostream&gt; const int maxn=10010; int father[maxn]; int findfather(int x){ int a=x; while(x!=father[x]) x=father[x]; while(a!=father[a]){ int temp=father[a]; father[a]=x; a=te...

weixin_37565706的博客 323

PAT A1118. Birds in Forest

1118. Birds in Forest (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Some scientists took pictures of thousands of birds in a f

u014226072的专栏 243

PAT A1118 2019.08.31 【并查集】

1118Birds in Forest(25分) Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the...

一个非计算机专业的 博客 245

1118 并查集

这道并查集其实很简单,circul别搞错就行 复制相似代码一定把变量改过来,尽量少偷懒 /* 并查集:一种树形结构,后存储数据,查找只需线性的复杂度 存的是鸟不是树 */ #include #include #include #include using namespace std; const int maxn=10005; int ans[maxn]={0},father[max

智浩的博客 270

【PAT】A1118 Birds in Forest 【并查集】

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi...

elegant coder 626

1118. Birds in Forest (25)[并查集]

1. 原题:https://www.patest.cn/contests/pat-a-practise/1118 2. 思路: 题意:考察并查集。每张图片里的鸟儿都在一棵树上,判断有几棵树。 思路: 首先要对并查集熟悉。一个参考:http://dongxicheng.org/structure/union-find-set/ 其实并查集就两个函数,一个合并,一个寻根。 了解并查集,这题

坚不萌 347

PAT A1118 Birds in Forest

PAT A1118 Birds in Forest Sample Input: 4 3 10 1 2 2 3 4 4 1 5 7 8 3 9 6 4 2 10 5 3 7 Sample Output: 2 10 Yes No 思路 1: 并查集:同A1107. Social Clusters code 1: #include <iostream> #include &...

qq_42347617的博客 142

PAT(A) 1118. Birds in Forest (25)

原题目: 原题链接:https://www.patest.cn/contests/pat-a-practise/1118 1118. Birds in Forest (25) Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appea...

萧易桥的博客 303

PAT A 1116 1117 1118 1119

1116 判断素数 STL 题目大意: 冠军会得到 “Mystery Award” ,排名为素数的人得到 the Minions 。其他人得到 chocolates。给你比赛排名 以及 参赛者的id,请你找出大家都的什么奖 。 #include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;map&gt; #include&lt;s...

大美mixer的博客 239

PAT-A1118

#include #include #include using namespace std; int n, Q, sum=0; int father[10010]; bool isfather[10010]={false}; set st; int findfather(int x){ int a=x, aa; while(father[x]!=x){ x=father[x]; }

qq_2918的博客 347

PAT A 1118 AC代码

考察并查集 注意使用路径压缩的写法,否则会超时(路径压缩后,findfather函数可以看作时间复杂度为O(1)的函数) 其余都是简单并查集逻辑 #include<iostream> #include<set> using namespace std; set<int> birds; int father[10001]; int findfather(int x){ if(father[x]==x){ return x; }else{ int F=fi

maxleo928的博客 114
上一篇: PAT a1120
下一篇: PAT a1119
CSlerner
博客等级 码龄9年 153粉丝 55原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值