Red and Black
来源:互联网 发布:什么软件看漫画免费 编辑:程序博客网 时间:2024/05/16 11:56
题目的大概意思是:一个人从@点出发,向4个方向走,只能走‘.'的区域,问能走的格子有多少个
简单的dfs
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int w,h;char c[25][25];int v[25][25];int sum;int x[4]={1,-1,0,0};int y[4]={0,0,1,-1};void dfs(int i,int j){ int a,b; v[i][j]=1; for(int k=0;k<4;k++) { a=i+x[k]; b=j+y[k]; if(a>=0&&a<h&&b>=0&&b<w&&v[a][b]==0&&c[a][b]=='.') { sum++; dfs(a,b); } }}int main(){ while(scanf("%d%d",&w,&h)!=0) { if(w==0&&h==0) return 0; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { cin>>c[i][j]; } } memset(v,0,sizeof(v)); for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { if(c[i][j]=='@') { sum=1; dfs(i,j); cout<<sum<<endl; } } } } return 0;}
0 0
- Red and Black
- red and black
- HDUOJ1312 Red and Black
- Red and Black
- red and black
- Red and Black
- HDOJ Red and Black
- HDU1312( Red and Black )
- Red and Black
- hdu1312 Red and Black
- 深搜:Red and Black
- 1038 Red and Black
- HDU1312 Red and Black
- HDU Red and Black
- Red and Black
- HDU1312:Red and Black
- 1001Red and Black
- Red and Black 搜索
- python错误 ImportError: No module named setuptools 解决方法
- Java内存区域
- 5-1. 约分最简分式(15)
- 诗意行走
- 动态设置控件大小位置
- Red and Black
- HDU 1754 I Hate It
- LeetCode:Implement strStr()
- android第三方登录以及第三方分享
- win8.1系统vs2013中boost 1.55.0的安装
- KMP算法
- 01背包(模板题) 之 poj 3624
- poj2262 Goldbach's Conjecture 素数的欧拉筛法
- 线程 同步 ConditionVariable-------特别使用在mediaplayer和camera多次调用中.