首页 > 代码库 > hdu-1312 Red and Black
hdu-1312 Red and Black
http://acm.hdu.edu.cn/showproblem.php?pid=1312
题意:在图中给定一个人的起点,问他能达到的最多地方是多少,‘.‘表示能走,’#‘不能走。
思路:找出起点,直接扩展就好了。
#include<cstdio> #include<cstring> char map[21][21]; int dir[4][2]={-1,0,1,0,0,1,0,-1}; int n,m,count; void dfs(int x,int y) { for(int i=0;i<4;i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(xx>=0&&xx<n&&yy>=0&&yy<m&&map[xx][yy]=='.') { map[xx][yy]='#'; count++; dfs(xx,yy); } } } int main() { int a,b; while(scanf("%d%d",&m,&n)!=EOF) { if(n==0&&m==0) break; for(int i=0;i<n;i++) { scanf("%s",map[i]); for(int j=0;j<m;j++) if(map[i][j]=='@') { count=1; a=i;b=j; } } dfs(a,b); printf("%d\n",count); } return 0; }
hdu-1312 Red and Black
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。