首页 > 其他分享 >uva 784 Maze Exploration(DFS遍历图)

uva 784 Maze Exploration(DFS遍历图)

时间:2023-07-26 17:33:02浏览次数:36  
标签:784 map cnt room int DFS Exploration XXXXX ###


                         uva 784 Maze Exploration


maze(迷宫) of rectangular(矩形的) rooms is represented on a two dimensional(空间的) grid as illustrated(阐明) in figure 1a. Each point of the grid is represented by a character. The points of room walls are marked by the same character which can be any printable(印得出的) character different than `*', `_' and space. In figure 1 this character is `X'. All the other points of the grid are marked by spaces.


XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX X X X X X X X###X###X###X X X X X X X X###########X X X X X X X X X X###X###X###X X X XXXXXX XXX XXXXXXXXXX XXXXXX#XXX#XXXXXXXXXX X X X X X X X X###X###X###X###X X X * X X X###############X X X X X X X X X###X###X###X###X XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX


maze (迷宫)                    b) Painted maze

Figure 1. Mazes of rectangular(矩形的)


illustrated(阐明)


door | XX XX X . X measured from within the room door - ...-- walls are 3 points wide X . X__ XXXXX | |___ walls are one point thick


Figure 2. A room with 3 doors


*') positioned in the middle of the room. A room can be visited from another room if there is a door on the wall which separates the rooms. By convention(大会), a room is painted if its entire surface, including the doors, is marked by the character `#' as shown in figure 1b.

Input 


The program input(投入) is a text file structured(有结构的)


positive (积极的) integer (整数) 2. The rest of the file contains the mazes.

terminated(终止) by a separation line full of underscores(底线) (`_'). There are at most 30 lines and at most 80 characters in a line for each maze(迷宫)

input(投入) file, paints them and writes the painted mazes on the standard output(输出).

Output 


The output text of a painted maze has the same format as that which has been read for that maze, including the separation lines. The example below illustrates(阐明)

Sample Input 


2 XXXXXXXXX X X X X * X X X X XXXXXXXXX X X X X X X XXXXX _____ XXXXX X X X * X X X XXXXX _____


Sample Output 


XXXXXXXXX X###X###X X#######X X###X###X XXXXXXXXX X X X X X X XXXXX _____ XXXXX X###X X###X X###X XXXXX _____



题目大意:将可以走到的地方标记成'#'(下划线是终止一组数据)

解题思路:DFS遍历的同时直接修改map.


#include<stdio.h>
#include<string.h>
char map[35][85], cnt = 0;
void DFS(int a, int b) {
	map[a][b] = '#';
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (i == 0 && j == 0) {
				continue;
			}
			if (a + i < 0 || a + i > cnt) {
				continue;
			}	
			if (b + j < 0 || b + j > strlen(map[a + i])) {
				continue;
			}
			if (map[a + i][b + j] == '#' || map[a + i][b + j] == 'X') {
				continue;
			}
			DFS(a + i, b + j);
		}
	}
}	
int main() {
	int n;
	scanf("%d\n", &n);
	while (n--) {
		memset(map, 0, sizeof(map));
		cnt = 0;
		while (gets(map[cnt]) != NULL) {  
			if (strcmp(map[cnt], "_____") == 0) { 
				break;  
			}
			cnt++;  
		}
		for (int i = 0; i <= cnt; i++) {
			for (int j = 0; j < strlen(map[i]); j++) {
				if (map[i][j] == '*') {
					DFS(i, j);
				}
			}
		}
		for (int i = 0; i <= cnt; i++) {
			puts(map[i]);
		}
	}
	return 0;
}








标签:784,map,cnt,room,int,DFS,Exploration,XXXXX,###
From: https://blog.51cto.com/u_16206136/6858297

相关文章

  • 英杰们的蛋糕塔(dfs)(难)
     题解:这道题的关键是找到状态转移方程,从最底层(n)开始,计算上面全部(n,n-1,n-2……1)层的总表面积和总体积,从而来确定使表面积最小的S1#include<bits/stdc++.h>2usingnamespacestd;3#defineS(r)((r)*(r))//底面积4#defineC(r,h)(2*......
  • linux下载安装fastdfs和fastdfs与nginx整合、springboot访问fastdfs
    文章目录需求分析分布式文件系统1FastDFS安装FastDFS和nginx整合2.整合java访问fastdfs服务文件上传查询下载测试整合springboot需求分析搭建fastDFS文件服务器1)安装fastDFStracker和storage2)在storageserver上安装nginx在storageserver上安装nginx的目的是对外通过http访问......
  • HDFS High Availability
    HDFSHighAvailabilityHDFSHighAvailabilityPurposeNote:UsingtheQuorumJournalManagerorConventionalSharedStorageBackgroundArchitectureHardwareresourcesDeploymentConfigurationoverviewConfigurationdetailsDeploymentdetailsAdministrativecommandsA......
  • HDFS High Availability Using the Quorum Journal Manager
    HDFSHighAvailabilityUsingtheQuorumJournalManagerHDFSHighAvailabilityUsingtheQuorumJournalManagerPurposeNote:UsingtheQuorumJournalManagerorConventionalSharedStorageBackgroundArchitectureHardwareresourcesDeploymentConfigurationoverv......
  • 组合的输出 dfs
    #include<bits/stdc++.h>usingnamespacestd;inta[101];intm,n;voids(intk){inti;if(k>m){for(i=1;i<=m;i++){cout<<setw(3)<<a[i];}cout<<endl;return;}for......
  • 搜索(DFS/BFS)
    广度优先搜索(BFS)基本要点: -利用队列(先进先出) -一层一层搜索 -适合于连通块的搜索 -任何的BFS都可以转化为对树的广搜基本流程: -选择搜索的起点,起点入队,起点标记为已访问 -队列非空时,循环出队,每次出队将与出队元素连通的且未访问过的元素依次入队,并......
  • 冷门科技 —— DFS 序求 LCA
    Updateon2023.7.17:该技巧目前已知的最早来源:skip2004。Updateon2023.7.17:比较时,取时间戳较小的结点也是正确的,不用记录深度。DFS序求LCA无论是从时间常数,空间常数还是好写程度方面均吊打欧拉序。定义DFS序表示对一棵树进行深度优先搜索得到的结点序列,而时间戳DFN......
  • 小明以 hadoop 用户身份在 HDFS 上 hadoop 目录下创建 expl 目录时,发现该目
    使用Hadoop创建目录引言Hadoop是一个开源的分布式计算框架,提供了可靠性和高可扩展性的存储和处理大数据的能力。其中的分布式文件系统HDFS(HadoopDistributedFileSystem)是Hadoop的核心组件之一,用于存储和管理海量数据。在HDFS上进行目录和文件的操作是使用Hadoop命令行工具或者......
  • SaeweedFS操作
    #mdir存储元数据的数据目录#port监听端口#peers主节点ip:端口#defaultReplication备份策略#ip服务器ip#garbageThreshold清空和回收空间的阈值#maxCpu最大cpu数量,0是所有#pulseSeconds心跳检测的时间间隔单位为秒#ip.bind绑......
  • Docker安装的fastdfs基于不同服务器的数据迁移
    首先,基于docker搭建新的fastdfs中间件,参考地址为:https://blog.csdn.net/ming19951224/article/details/126933299然后将原服务器的storage文件夹下的data文件夹进行备份,打包成bak.zip 将bak.zip下载后上传到新服务器的storage文件夹下 使用unzip解压缩bak.zip,然后进入data.......