HDU 1312 Red and Black

来源:互联网 发布:mac 最近使用字体 编辑:程序博客网 时间:2024/06/04 07:04

裸的不能再裸了==上个假期都会做==

#include <iostream>#include<cstdio>using namespace std;int w,h;char z[21][21];int dfs(int i,int j){    if(i<1||i>h||j<1||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(){ //   freopen("cin.txt","r",stdin);    while(cin>>w>>h)    {        if(w==0&&h==0) 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;        }    }    return 0;}


0 0