POJ 1979 Red and Black
来源:互联网 发布:网络教育统考报名网 编辑:程序博客网 时间:2024/04/26 20:15
原题链接
思路:经典深搜
AC代码:
#include <iostream>#include <cstdio> #include <algorithm>#include <cstdlib>#include <cstring>#include <queue>using namespace std;//与POJ_2386水洼题相似 //dfs深度优先搜索 int ans,dis[21][21],w,h;char room[21][21];int dx[4]={1,0,0,-1};int dy[4]={0,1,-1,0};void dfs(int x,int y){ int i; for(i=0;i<4;i++){ int x0=x+dx[i],y0=y+dy[i]; if(room[x0][y0]=='.' && dis[x0][y0]==0 && x0>=0 && y0>=0 && x0<h && y0<w){ dis[x0][y0]=1; ans++; dfs(x0,y0); } } return; } int main(){ int i,j,x0,y0; cin>>w>>h; getchar(); while(w||h){ ans=0; memset(dis,0,sizeof(dis)); for(i=0;i<h;i++) gets(room[i]); for(i=0;i<h;i++){ for(j=0;j<w;j++){ if(room[i][j]=='@'){ dis[i][j]=1; ans++; dfs(i,j); } } } printf("%d\n",ans); cin>>w>>h; getchar(); } return 0;}
1 0
- 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
- POJ 1979 Red and Black
- poj 1979 Red and Black
- POJ 1979 Red and Black
- poj 1979Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- POJ 1979-Red and Black
- 【第16题】360校园招聘2015届技术类笔试题
- grep命令
- 收录SQL常用语句大全
- Linux usb子系统(一) _写一个usb鼠标驱动
- 配置描述符介绍
- POJ 1979 Red and Black
- 【第17题】360校园招聘2015届技术类笔试题
- java并发与多线程总结
- Tensorflow在Android上的应用(Windows、Mac、Linux)
- 在angular-cli项目中使用Scss和Pug(Jade)模板引擎
- 使用Ecplise git commit时出现"There are no stages files"
- python入门(四)
- PAT L2-006【二叉树中序后序构造树】
- 计算机组成原理学习1: C/C++编译器中字节对齐的原理