文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>1039.Treausure

1039.Treausure

时间:2010-11-10  来源:gzzcracker

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int x[] = {-1, 0, 1, 0};
int y[] = {0, 1, 0, -1};
char s[1000][1001];
int n, m;

bool bound(int cx, int cy) {
    if (cx >= 0 && cx < n && cy >= 0 && cy < m)
        return true;
    return false;
}

int dfs(int cx, int cy) {
    int nx, ny, nr = 0;
    if (s[cx][cy] == '*')
        nr++;
    s[cx][cy] = '#';
    for (int i = 0; i < 4; i++) {
        nx = cx + x[i];
        ny = cy + y[i];
        if (bound(nx, ny) && s[nx][ny] != '#')
            nr += dfs(nx, ny);
    }
    return nr;
}

int main(int argc, char* argv[]) {
    int i, j, cx, cy;
    bool mark;

    while (scanf("%d", &n) != EOF) {
        scanf("%d", &m);
        mark = false;
        for (i = 0; i < n; i++) {
            scanf("%s", s[i]);
            if (mark)
                continue;
            for (j = 0; j < m; j++) {
                if (s[i][j] == 'X') {
                    cx = i;
                    cy = j;
                    mark = true;
                    break;
                }
            }
        }
        printf("%d\n", dfs(cx, cy));
    }

    return 0;
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载