NEC Programming Contest 2021(AtCoder Beginner Contest 229) A - First Grid

题目链接:A - First Grid (atcoder.jp)

Problem Statement

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

Input is given from Standard Input in the following format:

S1​
S2​

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.

题意:有2行2列四个格子,每个格子都有颜色,要么黑色,要么白色,问黑格子是否全部连在一起(有一条公共边就算连在一起)

思路,只有2个黑格子的需要考虑:对角是不行的

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


int main(){
	string s[5];
	for(int i = 0; i <= 1; i++){
		cin >> s[i];
	}
	int ans = 0;
	for(int i = 0; i < 2; i++){
		for(int l = 0; l < 2; l++){
			if(s[i][l] == '#'){
				ans++;
			}
		}
	}
	if(ans == 2){
		if(s[0][0] == '#' && s[1][1] == '#'){
			cout << "No" << endl;
		}else if(s[0][1] == '#' && s[1][0] == '#'){
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl;
		}
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值