码迷,mamicode.com
首页 > 其他好文 > 详细

HDU-1312-Red and Black

时间:2014-10-05 22:19:08      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   for   sp   div   c   代码   amp   

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1312

此题注意n,m 表示到底是行还是列

代码

#include<stdio.h>

#include<string.h>
 
int n,m,cnt;
char s[30][30];
int to[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
 
 
void dfs(int i,int j)
{
    cnt++;
    s[i][j]=‘#‘;
    int k;
    for(k=0;k<4;k++)
    {
        int x=i+to[k][0];
        int y=j+to[k][1];
        if(x>=0&&x<n&&y>=0&&y<m&&s[x][y]==‘.‘)
        dfs(x,y);
    }
}
int main(void)
{
    int i,j;
    int fi,fj;
    while(scanf("%d%d",&m,&n)==2&&(n+m))
    {
        getchar();
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%c",&s[i][j]);
                if(s[i][j]==‘@‘)
                {
                    fi=i;
                    fj=j;
                }
            }
            getchar();
        }
        cnt=0;
        s[fi][fj]=‘#‘;
        dfs(fi,fj);
        printf("%d\n",cnt);
    }
    return 0;
}

 

HDU-1312-Red and Black

标签:http   io   ar   for   sp   div   c   代码   amp   

原文地址:http://www.cnblogs.com/liudehao/p/4007371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!