【hdu 1312】 Red and Black (dfs+bfs)

本文介绍了一个基于深度优先搜索算法的程序,该程序用于计算在一个由黑色和红色方块组成的矩形房间中,从一个指定的黑色方块出发可以到达的所有黑色方块的数量。通过递归的方式遍历所有可达的黑色方块。

A - Red and Black

 
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. 

Write a program to count the number of black tiles which he can reach by repeating the moves described above. 
Input
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20. 

There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows. 

'.' - a black tile 
'#' - a red tile 
'@' - a man on a black tile(appears exactly once in a data set) 
Output
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself). 
Sample Input
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
Sample Output
45
59
6
13


代码:

#include<cstdio>
int x_move[4]={0,0,1,-1};
int y_move[4]={1,-1,0,0};
int w,h,num,i,j;
char map[25][25];
void dfs(int x,int y)
{
	if(x<0||y<0||x>=w||y>=h)
	    return ;
	if(map[x][y]=='#')
	    return ;
	map[x][y]='#';
	num++;
	for(int i=0;i<4;i++)
	    dfs(x+x_move[i],y+y_move[i]);
}
int main()
{
	while(~scanf("%d%d",&h,&w)&&h&&w)
	{
		num=0;
		for(i=0;i<w;i++)
		   scanf("%s",map[i]);  
		for(i=0;i<w;i++)
		{
			for(j=0;j<h;j++)
			{
				if(map[i][j]=='@')
				dfs(i,j);
			}
		}
		printf("%d\n",num);
	}
	return 0;
}


内容概要:本文介绍了一个基于Python的地理空间分析自动化流程,旨在利用Google Earth Engine(GEE)获取森林分类遥感数据,并结合GIS技术对特定不动产区域内的森林类型进行可视化与面积统计。系统通过加载不动产矢量边界(AOI),从GEE平台调用NASA/ORNL发布的全球森林分类数据集(2020年版),裁剪并下载对应区域的栅格数据,随后在本地进行像素级分类统计,计算各类森林(原始林、年轻次生林、老年次生林)的覆盖面积(单位:公顷)。同时,程序生成标准化的地图可视化结果,包含底图、图例、比例尺、指北针和智能经纬网格,并最终导出包含图表和统计表格的PDF报告。整个流程实现了从云端数据获取到本地制图输出的一体化处理。; 适合人群:具备Python编程基础及地理信息系统(GIS)知识的科研人员、环境监测从业者或遥感技术人员,尤其适合从事生态评估、土地利用分析等相关工作的专业人士;; 使用场景及目标:① 实现对指定区域森林类型的自动分类与面积量化;② 生成符合出版标准的空间地图与分析报告,支持环境保护、碳汇评估或政策制定等应用;③ 提供可复用的自动化管道,减少重复性人工操作; 阅读建议:此资源以面向对象方式组织代码,结构清晰,建议使用者熟悉geemap、rasterio、geopandas等库的基本用法,并确保已配置GEE开发环境。学习时应重点关注类间的协作关系、坐标系处理逻辑以及地图美化细节,便于根据实际需求扩展分类体系或调整输出样式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值