POJ 1979 :Red and Black 搜索
来源:互联网 发布:软件系统的作用 编辑:程序博客网 时间:2024/06/06 20:12
题意:给你一个row*col的矩阵,上面的'#'代表你不能走的地方,'.'表示你能走的地方,'@'表示你的起点,问你最多能走多少格。
还是求连到一起的方块。。。但是一开始输入写反了,旋转了90度(之前已经犯过一次这种错误了。。。),WA了好久。
#include <iostream>#include <string.h>#include <stdio.h>#include <math.h>#include <map>#include<queue>using namespace std;int xa,ya;bool isok[105][105];int cnt;void dfs(int x,int y){ if((!isok[x][y])||x<0||y<0||x>=ya||y>=xa) return; isok[x][y]=false; dfs(x+1,y); dfs(x,y+1); dfs(x,y-1); dfs(x-1,y); cnt++;}int main(){ while(cin>>xa>>ya) { int posx,posy; if(!(xa||ya)) break; cnt=0; for(int i=0;i<ya;i++) { char c; for(int j=0;j<xa;j++) { cin>>c; if(c=='.') isok[i][j]=true; else if(c=='#') isok[i][j]=false; else if(c=='@') posx=i,posy=j,isok[i][j]=true; } } dfs(posx,posy); cout<<cnt<<endl; }}
0 0
- POJ 1979 Red and Black DFS搜索
- POJ 1979 Red and Black(搜索)
- POJ 1979 :Red and Black 搜索
- POJ 1979 Red and Black(BFS广度优先搜索)
- POJ 1979 Red and Black【深度优先搜索】
- poj 1979 Red and Black (简单裸搜索)
- Red and Black (POJ 1979,深度优先搜索)
- POJ 1979 Red and Black
- poj 1979 Red and Black
- POJ 1979 - Red and Black
- POJ-1979-Red and Black
- poj 1979 red and black
- poj 1979 Red and Black
- poj 1979 Red and Black
- POJ:1979 Red and Black
- POJ 1979 - Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- thinkphp杂项
- markdown语法
- Kotlin + RxJava = Functional Powerhouse
- Javascript自学-8
- 开发中如何合理地制造BUG
- POJ 1979 :Red and Black 搜索
- 文章标题
- 要学好linux运维请从排版画图开始
- Eclipse学习
- 清华EMBA课程系列思考之六 -- 比较文明视野下的中华领导智慧、企业管理与经济解析
- Android多线程断点下载
- Framework分析-Application的onCreate
- 电商行业的技术特点以及架构的弊端传统
- LeetCode90——SubsetII