主页
Featured image of post ACM练习——P2191 小Z的情书……

ACM练习——P2191 小Z的情书……

一言加载中_(:з」∠)_……

文章字数:404
预计阅读时长: 分钟

题目链接

题目分析

一般的模拟题……

模拟方阵顺时针转置……
公式:(x,y)—>(y,N-x+1)……
推出这个就行……

个人代码

//P2191 [小Z的情书](https://www.luogu.com.cn/problem/P2191)
#include <bits/stdc++.h>

#define MAX (1000 + 5)

#define node_MAX MAX *MAX
#define printX node[i].x
#define printY node[i].y
using namespace std;
int N, nodeNum = 0;
struct typeNode
{
	int x, y;
} node[node_MAX];
void rotate() //转置操作……
{
	for (int i = 1; i <= nodeNum; i++)
	{
		int tmp = node[i].x;
		node[i].x = node[i].y, node[i].y = N - tmp + 1;
	}
}
int cmp(typeNode node1, typeNode node2)
{
	return node1.x > node2.x ? 0 : (node1.x == node2.x ? node1.y < node2.y : 1);
}
int main()
{
	int times = 4;
	char letter[MAX][MAX], t;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
		{
			t = getchar();
			while (t != '#' && t != 'O')
				t = getchar();
			t == 'O' ? node[++nodeNum].x = i, node[nodeNum].y = j : 0;
		}
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
		{
			t = getchar();
			while (t < 'A' || t > 'Z')
				t = getchar();
			letter[i][j] = t;
		}
	
	while (times--) //times=4,四次操作
	{
		for (int i = 1; i <= nodeNum; i++)
			printf("%c", letter[printX][printY]);
		rotate();
		sort(node + 1, node + nodeNum + 1, cmp); //优化常数:存的只是符合输出的点,并非从头到尾遍历。因此转置后需要按输出顺序排序……
	}
}