首页 > 学院 > 开发设计 > 正文

hdu 1312

2019-11-08 02:42:52
字体:
来源:转载
供稿:网友
////  main.cpp//  dfs-bfs搜索////  Created by liuzhe on 16/8/10.//  Copyright © 2016年 my_code. All rights reserved.//#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int w,h;char z[21][21];int dfs(int i,int j){    if(i<1||j<1||i>h||j>w)        return 0;    if(z[i][j]!='#')    {        z[i][j]='#';        return 1+dfs(i-1,j)+dfs(i+1,j)+dfs(i,j-1)+dfs(i,j+1);    }    else        return 0;}int main(int argc, const char * argv[]) {    // insert code here...    while(cin>>w>>h)    {        if(!w&&!h)            break;        for(int i=1;i<=h;i++)            for(int j=1;j<=w;j++)                cin>>z[i][j];        for(int i=1;i<=h;i++)            for(int j=1;j<=w;j++)                if(z[i][j]=='@')                    cout<<dfs(i,j)<<endl;    }        //std::cout << "Hello, World!/n";    return 0;}
上一篇:Circular Sequence

下一篇:pyhton套件 Jupyter

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表