练习系统 实验四 red and black
来源:互联网 发布:js中new date 的参数 编辑:程序博客网 时间:2024/04/30 06:02
当前编程题:实验四 基础算法问题(16级)---Red and Black
1.问题描述
There is a rectangular room,covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
输入形式
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.
There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.
'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)
The end of the input is indicated by a line consisting of two zeros.
输出形式
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
样例输入
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
0 0
样例输出
45
中文翻译:
问题描述
有一个长方形的房间,用方瓷砖覆盖地面。瓷砖的颜色是红色或黑色。一个人站在一个黑色的瓷砖上。从一个瓷砖可以移动到相邻的四个瓷砖上。但他不能移动到红色瓷砖上,他仅可以在黑色的瓷砖上移动。
编写一个程序来计算他可以到达的黑瓷砖数量。
输入形式
输入由多组数据组成。一组数据由一个包含两个正整数W和H开始;W和H分别是在x和y方向的瓷砖数。W和H不超过20。
有H行的数据,其中每行包括W个字符。每个字符代表一个瓷砖的颜色。
'.' - 黑色瓷砖
'#' - 红色瓷砖
'@' -黑色瓷砖的一个人(在数据中只出现一次)
输入结束: 由两个零组成的数表示。
输出形式
对于每组数据,你的程序应该输出一行,包含了从最初的瓷砖开始可以达到的瓷砖数量(包括最初的瓷砖)。
#include<iostream>
using namespace std;
int W,H;
char aa[20][20];
int f(int x,int y)
{
if(x<0|| x>=H ||y<0 ||y>=W ||aa[x][y]=='#' )
{
return 0;
}
else
{
aa[x][y]='#';
return (1+f(x-1,y)+f(x+1,y)+f(x,y-1)+f(x,y+1));
}
}
int main()
{
int p,q;
while(1)
{
cin>>W>>H;
if(W==0 ||H==0)
{
break;
}
for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++)
{
cin>>aa[i][j];
if(aa[i][j]=='@') //啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊 我被这里坑到了 气的我都想砸电脑 怎么也找不出错 竟然是这里 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
p=i;q=j;
}
}
}
cout<<f(p,q)<<endl;
}
return 0;
}
0 0
- 练习系统 实验四 red and black
- Java程序练习-Red and Black
- 2013寒假练习 1038 Red and Black
- 课程练习二-1016-Red and Black
- 《数据结构编程实验》 3.2.1Red and Black
- Red and Black
- red and black
- HDUOJ1312 Red and Black
- Red and Black
- red and black
- Red and Black
- HDOJ Red and Black
- HDU1312( Red and Black )
- Red and Black
- hdu1312 Red and Black
- 深搜:Red and Black
- 1038 Red and Black
- HDU1312 Red and Black
- javascript点击空白位置关闭弹出层/点击包含指定区域但不属于指定区域的部分响应点击事件
- [问题]第一行代码_生命周期_you need to use a theme.appcompat theme (or descendant) with this activity
- 学生管理系统
- 题目1188:约瑟夫环
- 美团实习生面试题
- 练习系统 实验四 red and black
- SSH整合问题
- CentOS 6.5上升级openssh7.5
- DB2客户端连接不上db2默认端口50000
- L1-001. Hello World
- 蓝桥杯 数组排序去重
- orcle排序
- shell脚本根据某一列去重
- OpenCV—矩阵数据类型转换cv::convertTo