D - DomiNo Grid ZOJ - 2925

D - DomiNo Grid

 ZOJ - 2925 

Dominoes are small, flat, rectangular-shaped game pieces. Domino pieces are usually twice as long as they are wide and are usually made to be exactly half as thick as they are wide so that they can stand on edge without falling over. If we push one end of a queue of dominoes, the whole queue will fall over.

 

Now, you will be given some descriptions of domino grid with a '.' indicating an open space and an uppercase 'X' indicating a domino and the force used on one domino. You are to compute the ending descriptions. The force consists of two parts : location and direction. There are 8 directions shown below.

direction abbreviation
West : W
NorthWest : V
North : N
NorthEast : Y
East : E
SouthEast : Q
South : S
SouthWest : J

The falling direction of the pushed domino is always the same as the force. Other dominoes will fall over if: 1) it's adjacent with a previous fallen domino. 2) it's within 45 degree of the falling direction of the previous domino.

The direction of falling is the relative position of it to the previous fallen domino. No two dominoes will cause the same domino to fall over simultaneously. See the following example for more details.

XXX 
XXX 
XXX 

We say the outer 8 dominoes are adjacent with the middle one. With a force to east on the middle domino, the 3 dominoes in the third column will fall over and the direction will be northeast, east, southeast. So the ending grid is :

XXY 
XEE 
XXQ 

 

Input

 

There are multiple test cases. Each case begins with a line containing two positive integer n and m (1 <= n, m <= 500) that are the number of rows and columns of the grid. The next n lines each with m chars (only '.' and 'X') describe one row of the grid. At last, two integers i, j (ith row, jth column, both i and j start from 1) indicate the location of the force and a char C describes the direction of the force. You can assume that there is a domino at the location (i, j).

Process to the end of file.

 

Output

 

Print the ending description of the grid, using the abbreviations for the fallen dominoes.

Print a blank line between cases.

 

Sample Input

 

2 4
..XX
XX..
1 3 S
4 4
XXX.
...X
X..X
XXX.
3 1 E

 

Sample Output

 

..SX
WJ..

WWV.
...N
E..Y
XQE.

 

题目大意:

在一个map里,推动一个骨牌,他会带动即正前方、左侧45度和右侧45度的骨牌倒下,问当推动其中一个骨牌的时候,对应最后在map里倒下骨牌的方向和情况。

解题思路

从起始骨牌开始,不断将相邻的倒下骨牌的倾倒方向记录下来,直至没有新倒下的骨牌。用一个先进先出队列queue<Node> q保存已倒下但它引发的其它骨牌尚未处理的骨牌。队列的元素类型Node是格点的二维坐标。用二维地图类广搜的方式处理所有已倒下的骨牌,直至队列变空。广搜的解空间树是一个三叉树,每个结点最多扩展成3个新结点,分别是正前方、左侧45度和右侧45度的相邻格点。一旦新格点是合法格点且未曾倒下(标记是“X”),标记它倒下的方向。流程图如下。

 

用一个目标型二维数组记录倒下方向,为方便程序处理,倒下方向用序号0~7表示,因为记录格点矩阵的问题描述型二维数组仅出现“.”和“X”两种字符,与0~7不冲突,所以这两个数组可以合并,统一到一个字符型数组。

实现技巧:

(1)方向序号0~7,表示从East开始的8个逆时针排列的方向。在这种0-based的表示方式下,若当前方向为d,则三个新方向是(d-k+8) % 8 (k=-1, 0, 1),例如d=0(East),则三个新方向是7,0,1。

(2) 8个方向的序号和位移量如下图,用一个二维数组moves[8][2]表示:

       int moves[8][2] = {{1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1} };

则d方向的位移量(x,y)=(moves[d][0], moves[d][1])。

 

 

(3)方向字符需要转换为序号,方向序号也需要转换为字符。利用下面字符串及内联函数

char DirectChar[9] = "EYNVWJSQ";

inline int FromCharToNo(char dch)

{     return strchr(DirectChar, dch) - DirectChar;  }

可以实现双向的简洁转换。

序号d→字符:DirectChar[d];

字符dch→序号:fromCharToNo(dch)。

 

参考代码:

#include <string.h>
#include <iostream>
#include <queue>
using namespace std;

int n, m;
char map[502][502];	// 开始保存的字符只是'.'或'X',后来还有0~7 

struct Node {	//队列结点类型
	int x, y;
	int d;	// d:0~7, 方向序号,从 EAST逆时针转到 SOUTHEAST
	Node(int x0=0, int y0=0, int d0=0) : x(x0), y(y0), d(d0) {};	// 构造函数
};
int moves[8][2] = {{1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1} };
					// 位移数组moves[d]
char DirectChar[9] = "EYNVWJSQ";	// 方向序号->字符 
inline int FromCharToNo(char dch)
{	// 方向字符->序号 
	return strchr(DirectChar, dch) - DirectChar;
}

void bfs(int x, int y, int d)
{
	queue<Node> q;
	map[y][x] = d;
	q.push(Node(x, y, d));
	while (!q.empty()) {
		Node node = q.front();
		q.pop();
		for (int k = -1; k <= 1; k++) {	// 在三叉树上广搜 
			int nx, ny, nd;
			nd = (node.d + k + 8) % 8;
			nx = node.x + moves[nd][0];
			ny = node.y + moves[nd][1];
			if (ny >= 1 && ny <= n && nx >= 1 && nx <= m && map[ny][nx] == 'X') {
				map[ny][nx] = nd;
				q.push(Node(nx, ny, nd));
			}
		}
	}
}

int main()
{
	int x, y;
	int k = 0;	// case No.
	while (cin >> n >> m) {
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				cin >> map[i][j];
		char dch;
		cin >> y >> x >> dch;
		bfs(x, y, FromCharToNo(dch));
		if (k++)
			cout << endl;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++)
				if (map[i][j] >= 0 && map[i][j] <= 7)
					cout << DirectChar[map[i][j]];
				else
					cout << map[i][j];
			cout << endl;
		}
	}
	return 0;
}

 

内容概要:《2024年中国城市低空经济发展指数报告》由36氪研究院发布,指出低空经济作为新质生产力的代表,已成为中国经济新的增长点。报告从发展环境、资金投入、创新能力、基础支撑和发展成效五个维度构建了综合指数评价体系,评估了全国重点城市的低空经济发展状况。北京和深圳在总指数中名列前茅,分别以91.26和84.53的得分领先,展现出强大的资金投入、创新能力和基础支撑。低空经济主要涉及无人机、eVTOL(电动垂直起降飞行器)和直升机等产品,广泛应用于农业、物流、交通、应急救援等领域。政策支持、市场需求和技术进步共同推动了低空经济的快速发展,预计到2026年市场规模将突破万亿元。 适用人群:对低空经济发展感兴趣的政策制定者、投资者、企业和研究人员。 使用场景及目标:①了解低空经济的定义、分类和发展驱动力;②掌握低空经济的主要应用场景和市场规模预测;③评估各城市在低空经济发展中的表现和潜力;④为政策制定、投资决策和企业发展提供参考依据。 其他说明:报告强调了政策监管、产业生态建设和区域融合错位的重要性,提出了加强法律法规建设、人才储备和基础设施建设等建议。低空经济正加速向网络化、智能化、规模化和集聚化方向发展,各地应找准自身比较优势,实现差异化发展。
数据集一个高质量的医学图像数据集,专门用于脑肿瘤的检测和分类研究以下是关于这个数据集的详细介绍:该数据集包含5249张脑部MRI图像,分为训练集和验证集。每张图像都标注了边界框(Bounding Boxes),并按照脑肿瘤的类型分为四个类别:胶质瘤(Glioma)、脑膜瘤(Meningioma)、无肿瘤(No Tumor)和垂体瘤(Pituitary)。这些图像涵盖了不同的MRI扫描角度,包括矢状面、轴面和冠状面,能够全面覆盖脑部解剖结构,为模型训练提供了丰富多样的数据基础。高质量标注:边界框是通过LabelImg工具手动标注的,标注过程严谨,确保了标注的准确性和可靠性。多角度覆盖:图像从不同的MRI扫描角度拍摄,包括矢状面、轴面和冠状面,能够全面覆盖脑部解剖结构。数据清洗与筛选:数据集在创建过程中经过了彻底的清洗,去除了噪声、错误标注和质量不佳的图像,保证了数据的高质量。该数据集非常适合用于训练和验证深度学习模型,以实现脑肿瘤的检测和分类。它为开发医学图像处理中的计算机视觉应用提供了坚实的基础,能够帮助研究人员和开发人员构建更准确、更可靠的脑肿瘤诊断系统。这个数据集为脑肿瘤检测和分类的研究提供了宝贵的资源,能够帮助研究人员开发出更准确、更高效的诊断工具,从而为脑肿瘤患者的早期诊断和治疗规划提供支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值