POJ2396 Lake Counting

2024-03-04 16:18
文章标签 lake counting poj2396

本文主要是介绍POJ2396 Lake Counting,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

暴力搜索经典题
挑战程序设计竞赛
题目链接

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 110;
char G[maxn][maxn];
int n, m, cnt = 0;
int dx[8] = {1, -1, 0, 0, -1, 1, 1, -1}; 
int dy[8] = {0, 0, 1, -1, -1, 1, -1, 1};  
void dfs(int u, int v){if(u < 0 || v < 0 || u >= n || v >= m || G[u][v] == '.') return;G[u][v] = '.';for(int i = 0; i < 8; i++){int a = u + dx[i], b = v + dy[i];dfs(a, b);}
}
int main(){scanf("%d %d", &n, &m);getchar(); //换行符 for(int i = 0; i< n; i++) {for(int j = 0; j < m; j++)scanf("%c",&G[i][j]);getchar(); //吸收换行符 }for(int i = 0; i< n; i++) for(int j = 0; j < m; j++){if(G[i][j] == '.') continue;dfs(i, j);cnt++;}printf("%d\n", cnt);		return 0;
}

这篇关于POJ2396 Lake Counting的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/773734

相关文章

POJ 2386 Lake Counting(DFS)

题目: http://poj.org/problem?id=2386 题解: 遍历一次,遇到w,一次DFS后,与此w连接的所有w都被替换成‘ . ’,直到遍历完图中不再存在w为止,总共进行DFS的次数就是答案了。 代码: #include<stdio.h>int N,M;char map[110][110];void dfs(int x,int y){map[x][y]='

重磅 | Delta Lake正式加入Linux基金会,重塑数据湖存储标准

大数据技术与架构 点击右侧关注,大数据开发领域最强公众号! 暴走大数据 点击右侧关注,暴走大数据! 作者:wwwzw By 暴走大数据 场景描述:2019年10月16日,在荷兰阿姆斯特丹举行的 Spark+AI 欧洲峰会上,DataBricks 和 Linux

[LeetCode] 338. Counting Bits

题:https://leetcode.com/problems/counting-bits/description/ 题目 Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary repres

《Zero-Shot Object Counting》CVPR2023

摘要 论文提出了一种新的计数设置,称为零样本对象计数(Zero-Shot Object Counting, ZSC),旨在测试时对任意类别的对象实例进行计数,而只需在测试时提供类别名称。现有的类无关计数方法需要人类标注的示例作为输入,这在许多实际应用中是不切实际的。ZSC方法不依赖于人类标注者,可以自动操作。研究者们提出了一种方法,可以从类别名称开始,准确识别出最佳的图像块(patches),用

Swift 3.0 学习 -- 计算字符数量 (Counting Characters)

在swift2.0的时候,可以通过调用全局countElements函数,并将字符串作为参数进行传递,可以获取该字符串的字符数量。如下: let unusualMenagerie = "Koala, Snail, Penguin, Dromedary"print("unusualMenagerie has \(countElements(unusualMenagerie)) charact

leetcode338 Counting Bits Java

Description Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array. Example: Fo

UVA 11401 Triangle Counting

中文详解请访问我的博客:http://xiaoshig.sinaapp.com/?p=128 You are given n rods of length 1, 2…, n. You have to pick any 3 of them & build a triangle. How many distinct triangles can you make? Note that, two

sdut2610--Boring Counting(二分+划分树)

Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the

论文笔记 A Large Contextual Dataset for Classification,Detection and Counting of Cars with Deep Learning

ECCV 2016的文章,首先建立了一个从上到下照的车辆影像数据集(即鸟瞰视角),并提出ResCeption神经网络进行训练,进一步建立residual learning with Inception-style layers,进行车辆数目的计算。该方法为车辆数目的计算的一种新方式:通过定位和密度估计方法。对于新的场景或新的目标计数也同样适用。 文章主要关注3个任务点:(1)两类的分类问题(2)

数据湖之Delta Lake

Delta Lake:数据湖存储层概述 Delta Lake 是一种开源的存储层技术,构建在 Apache Spark 的基础之上,旨在解决传统数据湖的可靠性、性能和数据一致性问题。它通过引入 ACID 事务、数据版本控制、时间旅行和统一的批处理与流处理等特性,显著提升了数据湖的可用性和数据管理能力。Delta Lake 由 Databricks 推出,现已成为现代数据湖架构的核心组件。