BIT1038Red and Black
来源:互联网 发布:流水账软件 编辑:程序博客网 时间:2024/06/06 03:15
之前在hduAC的代码由于年代过于久远已经找不到了。。。。重写。。
这题应该是BFS入门题,用BFS跑一下就过了
题意:
有多组样例,每组样例的第一行是矩阵的宽和高
接下来是个字符矩阵
.表示可走,#表示不可走,@为起点
求矩阵中人可以到达的地方的数目,人只能上下左右移动
#include<iostream>#include<algorithm>#include<cstdio>#include<queue>using namespace std;char board[30][30];//board[H-1][W-1]int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};class coordinate{public:int x,y;};int W,H;bool inBoard(coordinate a){return a.x>=0&&a.x<H&&a.y>=0&&a.y<W;}int main(){while(cin>>W>>H,W||H){coordinate start;//起点for(int i=0;i<H;i++){for(int j=0;j<W;j++){cin>>board[i][j];if(board[i][j]=='@'){start.x=i;start.y=j;}}}queue<coordinate>Q;Q.push(start);board[start.x][start.y]='#';int counter=0;while(!Q.empty()){coordinate temp=Q.front();Q.pop();counter++;for(int i=0;i<4;i++){coordinate patch;patch.x=temp.x+dir[i][0];patch.y=temp.y+dir[i][1];if(!inBoard(patch)){continue;}if(board[patch.x][patch.y]=='#'){continue;}Q.push(patch);board[patch.x][patch.y]='#';}}printf("%d\n",counter);}return 0;}
- BIT1038Red and Black
- Red and Black
- red and black
- POJ_1979_Red and Black
- poj1979Red and Black
- Black Berry and IPhone
- 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
- Black And White
- 1038 Red and Black
- HDU1312 Red and Black
- SLIP(串行线路网际协议)
- 服务器网页缓存的深入分析
- WinSock使用Select设置connect的超时
- 逻辑操作符和位操作符
- 8种心理影响你的人际关系
- BIT1038Red and Black
- inno setup 安装/卸载 弹出网页
- 【Javascript练习记录】htmlbox插件及ajax传输时的特殊符号处理
- JAVA资源操作的注意点
- 2013寒假练习 1010:Maximum Sum
- 函数参数传递
- Java中的Overload Overwrite Override
- mysql 存储过程编写(2)
- 构造函数