日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

练习系统 实验四 red and black

發布時間:2023/12/15 windows 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 练习系统 实验四 red and black 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

當前編程題:實驗四 基礎算法問題(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;
}

總結

以上是生活随笔為你收集整理的练习系统 实验四 red and black的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。