当前位置:网站首页>-red and black-
-red and black-
2022-08-10 01:47:00 【-JMY-】
Title description
There is a rectangular house with square tiles in red and black.You stand on one of the black tiles and can only move up, down, left, and right adjacent black tiles.Write a program that counts how many black tiles you can reach in total.
Enter
The first line is two integers W and H, representing the number of tiles in the x and y directions, respectively.Neither W nor H exceeds 20.In the next H lines, each line includes W characters.Each character represents the color of a tile, the rules are as follows
1) '.': black tile;
2) '#': white tile;
3) '@': black tile,And you stand on this tile.This character occurs only once in each dataset.
Output
Output a line showing the number of tiles you can reach from the initial position (including the initial position when counting).
Sample input
6 9 …#......#..............................#@...#.#..#.
Sample output
45
Reference code:
#include
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<
}
return 0;
}
边栏推荐
- 渗透测试与攻防对抗——漏洞扫描&逻辑漏洞(Part1)
- 走出迷宫的最少步数2
- 第十五章 mysql存储过程与存储函数课后练习
- MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
- Redis redisTemplate.execute 执行锁
- 深入理解Aarch64内存管理
- 构建平衡二叉树「建议收藏」
- WPF DataGrid using data templates
- Leecode-205. 同构字符串
- JVM Memory and Garbage Collection - 10. Direct Memory
猜你喜欢
随机推荐
Redis redisTemplate.execute 执行锁
-采花生-
Creo5.0入门教程赠素材
3.9 - 正规表达式和正规集 3.10 - 有限自动机
安全知识培训——消防安全
【剑指offer】第一题 第二题
考柏的感慨
微服务【同步和异步通讯详解】第6章
GoLang 使用 goroutine 停止的几种办法
20220808-一些想法
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
如何抑制告警风暴?
《MySQL入门很轻松》第4章:数据表中存放的数据类型
错误提示:Syntax error on token “function”, delete this token
深入理解Aarch64内存管理
算法---整数替换(Kotlin)
-Vector Dot Product-
【Django】缓存
dlopen failed: library "libtaml.so" not found
ETCD快速入门-02 ETCD安装