当前位置:网站首页>【Codeforces】 A. Computer Game
【Codeforces】 A. Computer Game
2022-07-27 15:35:00 【tsunaa】
A. Computer Game
题意:
给你一个2*N的格子,从(1,1)走到(2,n),可以上下左右走,也可以斜着走,每次走x,y步长不超过1。途中会有障碍物,问是否能走到(2,n)。已知(1,1)和(2,n)没有障碍物。
1代表有障碍物,0代表没有。
样例:

思路:
刚开始用dfs写,然后t了。后来看题解才发现很简单:
只要遇到上下都是1的,就走不了了。如:
0100 0010 0111
0100 或者 0110 或者 1010
所以只要遍历一遍,看是否有str(1)(i) == str(2)(i) 即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int t, n;
int flag;
string a[2];
int main(){
cin >> t;
while(t--){
cin >> n;
flag = 1;
a[0].clear(); a[1].clear();
cin >> a[0] >> a[1];
for(int i = 0; i < n; i++)
if( a[0][i] == '1' && a[1][i] == '1') flag = 0;
if(!flag) cout << "NO" << endl;
else cout << "YES" << endl;
}
}
边栏推荐
- Xcode releases test package testflight
- 在CRA创建的项目中使用@并让其识别@路径并给出路径提示
- Maximum number less than n
- 写好技术原创文章的一点建议
- 腾讯云上传使用
- 技术实践干货 | 从工作流到工作流
- Redis: configuring AOF does not work
- The chess robot broke the finger of a 7-year-old boy. Netizen: it violated the first law of robots
- 20 years ago, he was Ma Yun's biggest enemy
- 国产新冠口服药为什么是治艾滋病的药
猜你喜欢

Introduction to Alibaba eagle eye system

详解二叉树之堆

How does vs2019 C language run multiple projects at the same time, how to add multiple source files containing main functions in a project and debug and run them respectively

App crash collection and analysis

选择体育场馆的LED显示屏时应该注重哪些方面

Select structure

WebView basic use

Three table joint query 1

Chen Yili of ICT Institute: reducing cost and increasing efficiency is the greatest value of cloud native applications

阿里巴巴鹰眼系统简介
随机推荐
Tencent cloud upload
选择体育场馆的LED显示屏时应该注重哪些方面
每条你收藏的资讯背后,都离不开TA
Kubernetes第七篇:使用kubernetes部署prometheus+grafana监控系统(Kubernetes工作实践类)
Getting started with unity
科目三: 直线行驶
Hegong sky team vision training Day7 - vision, Jetson naon and d435i
Hidden iframe design details of SAP ui5 fileuploader
技术实践干货 | 从工作流到工作流
About paths mapping in SAP ui5 application ui5.yaml
Two table joint query 1
Purchase in Appstore
Introduction to Alibaba eagle eye system
MySQL: 函数
SAP UI5 FileUploader 使用的隐藏 iframe 和 form 元素的设计明细
Redis: configuring AOF does not work
关于 SAP UI5 应用 ui5.yaml 里的 paths 映射问题
Neural network implementation of handwritten numeral classification matlab
交换机和路由器技术-02-以太网交换机工作原理
.NET Core with 微服务 - 什么是微服务