当前位置:网站首页>-红与黑-
-红与黑-
2022-08-09 23:46:00 【-JMY-】
题目描述
有一间长方形的房子,地上铺了红色、黑色两种颜色的正方形瓷砖。你站在其中一块黑色的瓷砖上,只能向上下左右四个方向的相邻的黑色瓷砖移动。请写一个程序,计算你总共能够到达多少块黑色的瓷砖。
输入
第一行是两个整数W和H,分别表示x方向和y方向瓷砖的数量。W和H都不超过20。在接下来的H行中,每行包括W个字符。每个字符表示一块瓷砖的颜色,规则如下
1)‘.’:黑色的瓷砖;
2)‘#’:白色的瓷砖;
3)‘@’:黑色的瓷砖,并且你站在这块瓷砖上。该字符在每个数据集合中唯一出现一次。
输出
输出一行,显示你从初始位置出发能到达的瓷砖数(记数时包括初始位置的瓷砖)。
样例输入
6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#.
样例输出
45
参考代码:
#include<bits/stdc++.h>
using namespace std;
int w,h,l;
char s[105][105];
void around(int i,int j){
if(s[i][j]=='#'||i<1||i>w||j<1||j>h)
return;
s[i][j]='#';
l++;
around(i,j-1);
around(i-1,j);
around(i,j+1);
around(i+1,j);
return;
}
int main(){
cin>>h>>w;
for(int i=1;i<=w;i++)
for(int j=1;j<=h;j++)
cin>>s[i][j];
for(int i=1;i<=w;i++)
for(int j=1;j<=h;j++)
if(s[i][j]=='@'){
around(i,j);
cout<<l;
return 0;
}
return 0;
}
边栏推荐
- 深度剖析 Apache EventMesh 云原生分布式事件驱动架构
- 今日睡眠质量记录61分
- JVM内存和垃圾回收-10.直接内存
- deepstream学习笔记(三):deepstream-imagedata-multistream解析与接入适配yolov5模型测试
- 快速响应性智能型/智能响应性聚乙二醇纳米/还原响应型水凝胶的研究与制备
- pytest:如何在测试中编写和报告断言
- Enhanced Deep Residual Networks for Single Image Super-Resolution
- Leetcode80. 删除有序数组中的重复项 II
- YOLOV5 study notes (7) - training your own data set
- 数据的存储——C语言
猜你喜欢

ES6 Beginner to Mastery #13: Extension Methods for Arrays 2

WPF DataGrid 使用数据模板

Digital wallets, red sea ecological rapid introduction of small programs can help capture device entry wisdom

mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)

The older tester has just passed the "hurdle" of being 35 years old, and I want to tell you something from my heart

程序员从佩洛西窜访事件中可以学到什么?

【剑指offer】第一题 第二题

【毕业设计】 基于Stm32的家庭智能监控系统 - 单片机 图像识别 人体检测 AI

Leetcode79. 单词搜索

收银管理软件如何做好员工管理?
随机推荐
共创 Ray 中文社区,Ray Forward Meetup 2022 直播邀你参加!
Creo5.0 introductory tutorial free material
2022金九银十工作潮,怎么样才能成功跳槽面试拿到高薪呢?
[SUCTF 2019]CheckIn (.htaccess和.user.ini)
redis distributed lock code example
【Django】缓存
生成树和交换的总结
JSP简介
The older tester has just passed the "hurdle" of being 35 years old, and I want to tell you something from my heart
天猫全网商品详情封装接口
abicc 知:API compatibility report 介绍
C语言--数据的存储(上)
WPF DataGrid 使用数据模板
E - Sugoroku 3(期望dp)
[C language] Address book "Static Memory Version"
C语言学习之旅 【操作符(残缺版)】
《痞子衡嵌入式半月刊》 第 60 期
Redis 大 key 要如何处理?
快速响应性智能型/智能响应性聚乙二醇纳米/还原响应型水凝胶的研究与制备
考柏的感慨