跳到正文

休闲·娱乐

Problem E: That Breath of the Wild Windmill Puzzle

asymptotes__约 5 分钟
原文
文章信息与版本

文章信息

发布
2026年11月4日
收录
2026年11月4日
更新
2026年11月4日
篇幅
约 5 分钟

版本

  1. v1当前

Problem E: That Breath of the Wild Windmill Puzzle

NOTE: THIS PROBLEM HAS A 30 SECOND TIME LIMIT INSTEAD OF THE USUAL 10 SECONDS 注意:本题时限为 30 秒,而非常规的 10 秒

Description

One of the puzzles in the video game “Legend of Zelda: Breath of the Wild” places you near a rectangular grid of blocks. Some of the blocks have windmills mounted on them, which spin when air is blown through them. The remaining blocks have fans, which blow wind in a single direction (up, down, left, or right). A fan will blow wind in a straight line, spinning each windmill in that line, no matter how far away, and no matter what other objects are in between. A windmill will spin if one or more fans are pointed at it.

The goal of the puzzle is to make all of the windmills spin simultaneously by turning the fans. We’d like to do it in the least amount of moves possible. A “move” turns a block’s fan ninety degrees in either direction.

在游戏《塞尔达传说:旷野之息》里有这样一个谜题:一块矩形方格板,方格分为两种:风车、风扇。

  • 风车:被风吹到就会转动;所有不是风扇的格子都是风车。
  • 风扇:朝一个固定方向吹风(上、下、左、右)。风扇沿直线吹风,这条直线上的所有风车都会被吹动,不受中间其他格子阻挡,距离不限。只要至少有一个风扇的风向对准这个风车,风车就会转动。

你可以旋转风扇。一次操作可以把一个风扇顺时针或者逆时针旋转 90°,算作一步。 你的目标:调整所有风扇朝向,让所有风车同时转动,求最少操作步数。如果无解,输出 Impossible。

Input

Each input case will begin with two integers rr and cc (<10<10), the number of rows and columns of the grid. A value of r=c=0r=c=0 denotes end of input.

The next line will contain an integer nn (1≤n<101 \le n < 10), the number of fans.

On the next nn lines, there will be three integers rir_i cic_i did_i. rir_i and cic_i are integers denoting the row and column of the fan on the grid (positions start from 0). did_i will be one of the 4 characters {U,D,L,R}\{\texttt{U},\texttt{D},\texttt{L},\texttt{R}\}, signifying whether the fan is initially blowing air Up, Down, Left, or Right.

每组测试用例开头两个整数 r,cr,c(均小于 10),代表网格的行数、列数。 r=0r=0 且 c=0c=0 代表输入结束。

接下来一行一个整数 nn(1≤n<101\le n<10),代表风扇的数量。

之后 nn 行,每行给出 ri,ci,dir_i,c_i,d_i:

  • ri,cir_i,c_i:风扇所在格子坐标,下标从 0 开始;
  • did_i 为 U / D / L / R,分别代表初始风向:上、下、左、右。

Output

For each input case ii, output:

Case i: k\texttt{Case i: }k

where kk is the minimum number of turns of fans needed to make wind blow on all windmills.

If it is not possible to make the wind blow on all windmills, output:

Case i: Impossible\texttt{Case i: Impossible}

对于第 ii 组数据,输出:

Case i: k\texttt{Case i: }k

kk 是让所有风车被吹到的最小旋转步数。

如果不存在方案,输出:

Case i: Impossible\texttt{Case i: Impossible}

Sample Input

4 4 5 0 3 U 1 2 U 2 2 R 3 0 L 3 3 U 4 4 4 0 3 U 1 2 U 2 2 R 3 0 L 0 0

Sample Ouput

Case 1: 6 Case 2: Impossible

cb06ed5a90150d4f2e6863aeb9aceebd~tplv-a9rns2rl98-pc_smart_face_crop-v1_512_384.jfif

原文