Red and Black(HDU1312)(B)
来源:互联网 发布:刀剑乱舞极化数据 编辑:程序博客网 时间:2024/05/17 19:58
どこでもドア:http://acm.hdu.edu.cn/showproblem.php?pid=1312
就是吃豆豆的游戏。。’#’是墙,’.’是豆豆,’@’是怪兽。注意启始位置已经吃了一个豆豆。
AC CODE:
#include<iostream>#include<cstdio>#include<algorithm>#include <cmath>#include <cstring>#include <string>#include<sstream>#include<set>#include <cstdlib>#include<map>using namespace std;const int M=25;int n,m,ans,sx,sy,vis[M][M];char ma[M][M];int dir[4][2]={1,0,0,1,-1,0,0,-1};//上下左右四个方向void DFS(int x,int y){ for(int k=0;k<4;k++) { int nx=x+dir[k][0]; int ny=y+dir[k][1]; //不越界不是墙就合法(此处可优化:不用判断访问状态,吃过的豆豆直接变成墙) if(nx>=0&&ny>=0&&nx<n&&ny<m&&!vis[nx][ny]&&ma[nx][ny]!='#') { vis[nx][ny]=1; ans++; DFS(nx,ny); } } return ;}int main(){ while(cin>>m>>n) { string str; memset(vis,0,sizeof(vis)); ans=1; //启始位置已经吃了一个豆豆 if(n==0&&m==0) break; for(int i=0;i<n;i++) { cin>>str; for(int j=0;j<m;j++) { ma[i][j]=str[j]; //记录启始位置 if(ma[i][j]=='@') { sx=i; sy=j; } } } vis[sx][sy]=1; DFS(sx,sy); cout<<ans<<endl; } return 0;}
0 0
- Red and Black(HDU1312)(B)
- HDU1312( Red and Black )
- hdu1312 Red and Black
- HDU1312 Red and Black
- HDU1312:Red and Black
- HDU1312 Red and Black
- Red and Black(hdu1312)
- HDU1312 Red and Black
- HDU1312 Red and Black
- HDU1312-Red and Black
- hdu1312 Red and Black
- hdu1312 Red and Black
- hdu1312 Red and Black
- HDU1312 Red and Black
- HDU1312 Red and Black
- hdu1312 Red and Black
- hdu1312--Red and Black
- HDU1312:Red and Black(DFS)
- Redis学习必备知识
- Kali Linux 秘籍 第八章 密码攻击
- Java bean 你所知道的一切
- java实现发送手机短信
- 词法分析主程序
- Red and Black(HDU1312)(B)
- 对仗(约瑟夫问题)
- VMware Workstation的简要介绍
- C 小技巧-换颜色
- JS学习(1)-JavaScript in HTML
- c++long和int的区别
- BP神经网络 c++实现
- 隔壁(贪心)
- 推荐子龙山人的emacs的教程