当前位置:网站首页>-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;
}
边栏推荐
猜你喜欢
Involved in PEG-Biotin (CAS: 1778736-18-7) Biotin-PEG4-OH is widely used in molecular target detection
数据的存储——C语言
阿雷的血压有些低
arm-4-裸板开发
LSTM-based distributed energy generation prediction (Matlab code implementation)
【C语言】通讯录《静态内存版本》
Description of AirFlow
CST Studio Suite 2021软件安装包和安装教程
深入理解Aarch64内存管理
足不出户也能看星空
随机推荐
从TRPO到PPO(理论分析与数学证明)
CAS:851113-28-5 (生物素-ahx-ahx-酪胺)
CAS:183896-00-6 (Biotin-PEG3-C3-NH2) PEG衍生物
天猫全网商品详情封装接口
深度剖析 Apache EventMesh 云原生分布式事件驱动架构
关于HBuilder X鼠标变为_ 替换字符的问题
线程的同步与互斥
JVM内存和垃圾回收-10.直接内存
Biotin-Cy2 Conjugate,生物素-Cy2 偶联物_Cy2 生物素偶联物
字节技术面都过了,薪资都谈好了20K*13结果还是被刷了,问HR原因是。。。
算法---整数替换(Kotlin)
20220808-一些想法
【obs】obsqsv11 硬编 及与metartc codec对比
Creo5.0入门教程赠素材
3.11-程序基本的控制语句 3.12-表达式 3.13-数据类型 3.14-常量/变量 3.15-标识符
How to activate the payment function on WeChat official account?
聚焦热点 | ISC 2022软件供应链安全治理与运营论坛圆满落幕
[NCTF2019]True XML cookbook-1|XXE漏洞
WPF DataGrid using data templates
c语言文件基本操作总结