First Grid
题目描述
We have a grid with 2 horizontal rows and 2 vertical columns.
Each of the squares is black or white, and there are at least 2 black squares.
The colors of the squares are given to you as strings S1 and S2, as follows.
If the j-th character of Si is #, the square at the i-th row from the top and j-th column from the left is black.
If the j-th character of Si is ., the square at the i-th row from the top and j-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 S1 and S2 is a string with two characters consisting of # and …
S1 and S2 have two or more #s in total.
输入
Input is given from Standard Input in the following format:
S1
S2
输出
If it is possible to travel from every black square to every black square, print Yes; otherwise, print No.
样例输入
【样例1】
##
.#
【样例2】
.#
#.
样例输出
【样例1】
Yes
【样例2】
No
提示
样例1解释
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.
样例2解释
It is impossible to travel between the top-right and bottom-left black squares, so the answer is No.
翻译
这题是说,给你四个方格,拍成一个正方形
正方形可以是黑色的,也可以是白色的
如果是黑色的,就会输入#
如果是白色的,就会输入.
题目保证会输入至少两个#
问你是不是所有的黑色方格都相通(只要他们有共同边就代表他们相通)
代码
放在洛谷里,这是红题了
其实我们发现,只有两种情况不是所有的黑色方格都相通
第一种
#.
.#
第二种
.#
#.
那么代码就出来了
#include<bits/stdc++.h>
using namespace std;
char a[2][2];
int main(){
cin>>a[0]>>a[1];
if((a[0][0]=='.'&&a[1][1]=='.')||(a[0][1]=='.'&&a[1][0]=='.'))
puts("No");
else
puts("Yes");
}