题P:First Grid

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");
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值