#abc229a. A - First Grid

A - First Grid

Score : 100100 points

问题描述

我们有一个包含 22 行横向和 22 列纵向的网格。
每个方格是黑色或白色,并且至少有 22 个黑色方格。
方格的颜色以字符串 S1S_1S2S_2 的形式给出,如下所示:

  • 如果 SiS_i 的第 jj 个字符为 #,则表示从上到下的第 ii 行、从左到右的第 jj 列的方格为黑色。
  • 如果 SiS_i 的第 jj 个字符为 ., 则表示从上到下的第 ii 行、从左到右的第 jj 列的方格为白色。

两个不同的黑色方格之间只有当它们相邻时才能相互移动。
判断是否可能通过只经过黑色方格(直接或间接)从任意一个黑色方格到达其他所有黑色方格。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a grid with 22 horizontal rows and 22 vertical columns.
Each of the squares is black or white, and there are at least 22 black squares.
The colors of the squares are given to you as strings S1S_1 and S2S_2, as follows.

  • If the jj-th character of SiS_i is #, the square at the ii-th row from the top and jj-th column from the left is black.
  • If the jj-th character of SiS_i is ., the square at the ii-th row from the top and jj-th column from the left is white.

You can travel between two different black squares if and only if they share a side.
Determine whether it is possible to travel from every black square to every black square (directly or indirectly) by only passing black squares.

Constraints

  • Each of S1S_1 and S2S_2 is a string with two characters consisting of # and ..
  • S1S_1 and S2S_2 have two or more #s in total.

Input

Input is given from Standard Input in the following format:

S1S_1

S2S_2

Output

If it is possible to travel from every black square to every black square, print Yes; otherwise, print No.

Sample Input 1

##
.#

Sample Output 1

Yes

It is possible to directly travel between the top-left and top-right black squares and between top-right and bottom-right squares.
These two moves enable us to travel from every black square to every black square, so the answer is Yes.

Sample Input 2

.#
#.

Sample Output 2

No

It is impossible to travel between the top-right and bottom-left black squares, so the answer is No.

update @ 2024/3/10 10:00:46