AV天天看,777精品出轨人妻国产,伊人久久综合精品无码av专区 ,麻豆一区二区大豆行情

AOJ 0118 Property Distribution {廣度優先搜索} -電腦資料

電腦資料 時間:2019-01-01 我要投稿
【www.seoerblog.net - 電腦資料】

   

題意

    原題是這樣的:

   

    原題呢就是上面這個,我還是來簡單翻譯一下吧,

AOJ 0118 Property Distribution {廣度優先搜索}

。<喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwPr+0tb3PwsPmtcTNvMHLw7Sjv7TzuMXT0DPW1s28sLi1xLHq1r6jrM/gzay1xL/J0tTGtL3Ttb3Su8bwo6zE49Do0qrV0rP21+6689K7ubLT0Lbgydm/6aGjscjI59XiwO+1xL7NysfT0DEwv+mhozwvcD4NCjxwPjxpbWcgYWx0PQ=="這里寫圖片描述" src="http://www.2cto.com/uploadfile/Collfiles/20151211/20151211082910159.jpg" title="\" />

    它的輸入是這樣的:

<code class="hljs" mel="">10 10####*****@@#@@@@#*#*@##***@@@*#****#*@**##@*#@@*##*@@@@*@@@#***#@*@##**@@@*@@##@*@*#*@##**@****#@@#@0 0</code>

    兩個0表示結束輸入,輸出塊的個數即可,上面的輸入對應的輸出就是33。

分析

    我還是用的這個給代碼定的規定,方向什么的。

   

    走過的點,全部都賦值為!,保證下次不會走到就好。for循環中進行判斷,每走一次就完成計算一塊,step也跟著加1,最后輸出其和即可。

代碼

<code class="hljs" cpp="">#include<iostream>using namespace std;#define MAX_W 100#define MAX_H 100char room[MAX_W][MAX_H];int W,H;const int direc[4][2] = {    {0, -1},    {1, 0},    {0, 1},    {-1, 0},};void dfs(const int& row, const int& col, const char c);int main() {    while(cin>>H>>W, W > 0) {        int step = 0;        int col, row;        for (row = 0; row < H; ++row) {            for (col = 0; col < W; ++col) {                cin >> room[row][col];            }        }        for (row = 0; row < H; ++ row) {            for(col = 0; col < W; ++ col) {                if(room[row][col] != '!') {                    dfs(row, col, room[row][col]);                    ++ step;                }            }        }        cout<<step<<endl; char="" const="" curcol="col" currow="" d="0;" int="" return="" void="">= 0 && curRow < H && curCol >= 0 && curCol < W && room[curRow][curCol] == c) {            dfs(curRow, curCol, c);        }    }}</step<<endl;></iostream></code>

最新文章
主站蜘蛛池模板: 嵩明县| 沁水县| 朝阳市| 苏州市| 黔东| 昌宁县| 馆陶县| 湖南省| 南木林县| 周口市| 湘阴县| 洪雅县| 广河县| 萨嘎县| 安岳县| 连州市| 新化县| 大洼县| 江津市| 即墨市| 江达县| 唐河县| 阿克苏市| 太湖县| 宁陕县| 吉林省| 勃利县| 瑞安市| 紫阳县| 涟源市| 平度市| 通州区| 区。| 东安县| 九江市| 绥德县| 绿春县| 高邑县| 郧西县| 日喀则市| 浪卡子县|