HDU 1312 Red and Black (DFS)
来源:互联网 发布:js字符串include 编辑:程序博客网 时间:2024/06/03 21:01
#include <stdio.h>#include <string.h>#include <math.h>char map[21][21];int w,h;int dx[]={-1,0,1,0};int dy[]={0,1,0,-1};//两个数组控制上下左右 int sum;void DFS(int x,int y){if(x<0||y<0||x>=h||y>=w)//走出地图 return ;if(map[x][y]=='#')//如果是红砖 return ;if(map[x][y]=='@'||map[x][y]=='.')//如果可走 {map[x][y]='#';//将走过的变为红砖,表明走过 sum++;//走过的次数加一 for(int i=0;i<4;i++)//四个方向循环 {int xx=x+dx[i];int yy=y+dy[i];//新坐标 DFS(xx,yy);//新坐标来DFS }}}int main(int argc, char *argv[]){while(scanf("%d %d",&w,&h)!=EOF){if(w==0&&h==0)break;sum=0;getchar();for(int i=0;i<h;i++){for(int j=0;j<w;j++)scanf("%c",&map[i][j]);getchar();}for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(map[i][j]=='@') { DFS(i,j);//找到@开始DFS }printf("%d\n",sum);}return 0;}//修订注释版1.0 //Start-ZJ//2017/9/22/9:25
阅读全文
0 0
- hdu 1312 Red and Black(dfs入门)
- hdu 1312 Red and Black dfs
- hdu 1312 Red and Black (简单dfs)
- hdu 题目1312 Red and Black ( DFS )
- HDU--1312 -- Red and Black [简单DFS]
- HDU 1312 Red and Black(BFS,DFS)
- HDU 1312 Red and Black (DFS入门)
- hdu 1312 Red and Black (bf、dfs)
- DFS-HDU 1312 -Red and Black
- hdu 1312 Red and Black(DFS)
- HDU--1312:Red and Black (DFS)
- HDU-#1312 Red and Black(DFS)
- HDU 1312 -- Red and Black(dfs)
- HDU 1312--Red and Black【DFS】
- HDU 1312Red and Black dfs
- hdu 1312 Red and Black(DFS)
- HDU - 1312 Red and Black (dfs)
- hdu 1312 Red and Black DFS
- POJ 1704 Georgia and Bob G++
- 23种设计模式(20):外观模式(1)
- MySQL utf8mb4 字符集,用于存储emoji表情
- ArcGIS API for Javascript Graphic心得
- 返回某个文件夹下所有的文件
- HDU 1312 Red and Black (DFS)
- 期货常识(华人投教)
- MFC全局函数开局——AfxGetApp解剖
- crontab 每分钟、每小时、每天、每周、每月、每年执行
- Java的四种引用类型详解
- 质量估计及其应用(Mass Estimation and Its Applications)
- springboot如何进行优化
- 微信小程序低功耗蓝牙
- 从苦逼到牛逼,详解Linux运维工程师的打怪升级之路