跳到正文

题解

FRT 正方体展开 题解

SunShine2012约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年7月8日
篇幅
约 2 分钟
获赞
1

版本

  1. v1当前

题目分析

搜索。模拟面的位置情况并判断是否有未定义的面即可。这里给出 dfs 代码。

完整代码

C++
#include <bits/stdc++.h>
using namespace std;

#define int long long
bool f[6];
int a[7][7], d[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}, r[6][4] = {{2, 5, 3, 4}, {2, 4, 3, 5}, {1, 5, 0, 4}, {0, 5, 1, 4}, {2, 0, 3, 1}, {2, 1, 3, 0}};
void dfs(int x, int y, int X, int Y, int v){
	if (!a[x][y]){
		for (int i = 0; i < 4; i++){
			int nx = x + d[i][0], ny = y + d[i][1];
			if (nx && nx < 7 && ny && ny < 7 && a[nx][ny] == -2) f[a[nx][ny] = r[0][i]] = 1, dfs(nx, ny, x, y, i ^ 2);
		}return;
	}int k = 0;
	for (; r[a[x][y]][k] != a[X][Y]; k++);
	for (int i = 1; i < 4; i++){
		int nx = x + d[v + i & 3][0], ny = y + d[v + i & 3][1];
		if (nx && nx < 7 && ny && ny < 7 && a[nx][ny] == -2) f[a[nx][ny] = r[a[x][y]][k + i & 3]] = 1, dfs(nx, ny, x, y, v + i & 3 ^ 2);
	}
}
signed main(){
	ios::sync_with_stdio(0), cin.tie(), cout.tie();
	memset(a, -1, sizeof a);
	int x, y;
	char c;
	for (int i = 1, j = 1, s = 0; s < 6; j++){
		c = getchar();
		if (c == '.') a[x = i][y = j] = -2, s++;
		if (c == '\n') i++, j = 0;
	}a[x][y] = 0, dfs(x, y, 0, 0, 0);
	for (int i = 1; i < 6; i++) if (!f[i]){cout << "Wrong."; return 0;}
	cout << "Perfect!";
	return 0;
}
原文