PAT a1118

Arduino DHT11 ESP8266 在OneNet云平台上读取 温湿度 #include "ESP8266.h" #include "dht11.h" #include "SoftwareSerial.h" #define SSID "540ND" #define PASSWORD "" #define HOST_NAME "api.heclouds.com" #define DEVICE_ID "" #define HOST_PORT (80) String APIKey = " "; #define INTER 阅读详情

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

输入:

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;
}

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

告别‘Duang’的一声:手把手解决RK3588开发板PCIe初始化卡死问题(DTS修改实战) 本文详细介绍了解决RK3588开发板PCIe初始化卡死问题的完整过程,包括问题诊断、DTS文件修改及编译烧写步骤。通过禁用未使用的PCIe硬件资源,有效解决了启动卡死问题,为嵌入式开发者提供了实用的调试方法和经验总结。 阅读详情

相关推荐

SPAD 单光子雪崩二极管

SPAD,全称为,是一种高灵敏度的光电探测器件,能够在非常低的光照水平下检测单个光子。SPAD在工作时,当一个光子被探测器吸收后,能够触发一个雪崩效应,产生一个可以被检测到的电信号。

qq_42786033的博客 1万+

【题解】【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

Origin画图——获取论文图中数据

有时候需要已发表论文的图的数据,这里使用Origin软件取值,并且可以实现对图形再次画图。 Step 1. 打开origin软件,点击工具,图形数字化工具。 Step 2. 打开要获取数据的图片。拉动红蓝坐标,与图的坐标轴所贴合。 Step 3. 打开要获取数据的图片。拉动红蓝坐标,与图的坐标轴所贴合。 Step 3. 设置参数横轴起始坐标为300-900,纵轴为1.8-2.6. Step 4. 点击第五个手动取点,取出图中数据点。 Step 5. 依次对原图进行取点。点击项目资源查看图。

qq_42278015的博客 5183

PAT A1118做题分析

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

weixin_44980441的博客 334

目标检测: 一文读懂 YOLOX

论文:YOLOX: Exceeding YOLO Series in 2021 论文链接:https://arxiv.org/pdf/2107.08430.pdf 代码链接:https://github.com/Megvii-BaseDetection/YOLOX. 文章目录1 为什么提出YOLOX2 YOLOX 网络架构3 YOLOX 实施细节3.1 backbone3.2 neck3.3 Head3.3.1 Decoupled Head3.3.2 Anchor-free3.4 如何计算Loss3.5 如

weixin_46142822的博客 3万+

LTspice introduction - 2 LTspice的界面

LTspice的界面主要有两个:Schematic Capture和Waveform Viewer Schematic Capture 它主要是用来画电路图的,画完电路图之后,添加一些dot 命令同时选择一些仿真的参数,点击执行(Run)Waveform Viewer 如果你的仿真不是op point的话,一个都会打开它,在它里面你可以画图相应的图形。 有两种方式可以在Viewer

贾亮的专栏 3220

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

利用随机矩阵理论(random matrix theory)确定微生物网络构建阈值

利用随机矩阵理论(random matrix theory)确定微生物网络构建阈值

微生物生态学分析 7638

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

YOLO模型从10MB瘦到2MB!剪枝+INT8量化双方案(精度损失<1%,附部署代码)

摘要:本文介绍了一种针对边缘设备的YOLO模型轻量化方案,通过"结构化剪枝+INT8量化"组合技术,将YOLOv8n模型从6.4MB压缩至2MB,体积减少68.75%,推理速度提升80%,同时保持精度损失小于1%。文章详细讲解了剪枝工具选择、通道剪枝实现、量化校准等关键步骤,并提供了完整的代码示例。特别强调了剪枝保留率、校准集使用、微调必要性等实践要点,帮助开发者在树莓派等资源受限设备上实现高效目标检测。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 756

TC8:SOMEIPSRV_SD_MESSAGE_07-09

TTL为服务实例的生命周期。在此生命周期之后,不提供服务实例。

jasonj333 908

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

RK3588 DDR5 方案

RK3588 DDR5方案支持多种LPDDR5/LPDDR5X内存型号,包括美光、三星、海力士、江波龙和佰维等品牌。文档详细列出了已验证的DDR5内存规格,涵盖2GB-16GB容量范围,提供组织形式、封装类型和测试状态等信息。其中美光型号最全面,支持12GB/16GB大容量方案。部分型号处于测试验证阶段(T/A),需量产进一步确认性能。该方案为RK3588平台开发提供可靠的内存选型参考。

501846585_QQAndroid_java 1082

第十四天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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

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

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

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

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值