首页 > 其他分享 >Red and Black HDU - 1312 (连通块的大小)

Red and Black HDU - 1312 (连通块的大小)

时间:2023-03-23 15:55:29浏览次数:40  
标签:HDU 1312 tx ty int dfs ++ Black ans

题意:求某点所在连通块的大小。
分析:由某点进行dfs,每次标记该点,并计数。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 110, INF = 0x3f3f3f3f;
string s[N];
int n, m, d[][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
int ans = 0;
void dfs(int x, int y) {
    ans++, s[x][y] = '*';
    for (int i = 0; i < 4; i++) {
        int tx = x + d[i][0], ty = y + d[i][1];
        if (tx < 0 || tx >= n || ty < 0 || ty >= m) continue;
        if (s[tx][ty] != '.') continue;
        dfs(tx, ty);
    }
}
int main() {
    while (cin >> m >> n && n) {
        for (int i = 0; i < n; i++) cin >> s[i];
        ans = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (s[i][j] == '@') dfs(i, j);
        cout << ans << endl;
    }
    return 0;
}

标签:HDU,1312,tx,ty,int,dfs,++,Black,ans
From: https://www.cnblogs.com/hellohebin/p/17247751.html

相关文章

  • 变形课 HDU - 1181 (dfs)
    题意:给定多个单词,每个单词的首字母可以到末字母,问能否由'b'到'm'。分析:将每个单词首尾字母建图,dfs('b')将能到的所有字母进行标记,最后检查'm'是否被标记。#include......
  • AtCoder Grand Contest 008 F Black Radius
    洛谷传送门AtCoder传送门神题!!!!111考虑如何不重不漏地计数。先考虑全为1的情况,令\(f(u,d)\)为与\(u\)的距离\(\led\)的点集。首先单独算全集,那么对于不是全集......
  • [HMV] Blackhat
    0x00配置攻击机IP:172.16.1.25靶机IP:172.16.1.1230x01攻击使用Nmap扫描目标靶机开放的端口┌──(root㉿Kali-VM)-[~]└─#nmap-sC-sV-p-172.16.1.123......
  • HDU 6514 Monitor
    注意:注意要用scanf注意多测#include<iostream>#include<vector>usingnamespacestd;intn,m,q;vector<vector<int>>a;voidinsert(intx1,inty1,intx......
  • HDU2199 Can you solve this equation? (二分查找)
    Canyousolvethisequation?TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):12794    AcceptedS......
  • F. Timofey and Black-White Tree 2100 (树 根号分治 思维)
    https://codeforces.com/problemset/problem/1790/F题意:给定一棵树,需要将其染为全黑,初始时只有一个点为黑色,给定一个序列c,按招顺序染色,要求每次染色后给出当前任意两黑点......
  • Prometheus黑盒测试【blackbox-exporter】
    官方下载地址blackbox-exporter是Prometheus官方提供的一个黑盒测试的解决方案,可用于以下使用场景:TCP:端口存活检测HTTP/HTTPS:可用性检测ICMP:主机存活检测TCP:端口存活......
  • hdu 5288 OO’s Sequence
    题目链接:​​http://acm.hdu.edu.cn/showproblem.php?pid=5288​​解法:定义两个数组L[i],R[i],表示第i数左侧和右侧最接近它且值是a[i]因子的数字的位置,那么第i个数能贡献......
  • hdu 5339 Untitled【搜索】
    题目链接:​​http://acm.hdu.edu.cn/showproblem.php?pid=5339​​题意:一个整数a和一个数组b,问你是否能在b中取出r个元素排列组成c数组满足a%c1%c1%…..%cr==0。输出最小......
  • hdu-2063 二分图
    http://acm.hdu.edu.cn/showproblem.php?pid=2063过山车TimeLimit:1000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmi......