当前位置:网站首页>【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;
}
}
边栏推荐
- 【SAML SSO解决方案】上海道宁为您带来SAML for ASP.NET/SAML for ASP.NET Core下载、试用、教程
- Can deep learning overturn video codec? The first prize winner of the National Technological Invention Award nags you in the little red book
- Built in object (bottom)
- Technical practice dry goods | from workflow to workflow
- 奇瑞欧萌达也太像长安UNI-T了,但长得像,产品力就像吗?
- 数据库超话(二)
- 微软默默给 curl 捐赠一万美元,半年后才通知
- MySQL: 函数
- Hidden iframe design details of SAP ui5 fileuploader
- Day 7 summary & homework
猜你喜欢

数据库超话(一)

基于STM32的智能鱼缸设计

Understand the basic properties of BOM and DOM

.net core with microservices - what is a microservice

微软默默给 curl 捐赠一万美元,半年后才通知

三表联查1

Gods at dusk, "cat trembles" bid farewell to the big V Era

苹果官网罕见打折,iPhone13全系优惠600元;国际象棋机器人弄伤对弈儿童手指;国内Go语言爱好者发起新编程语言|极客头条...

通过 FileUploader 的初始化,了解 SAP UI5 应用的 StaticArea 初始化逻辑

The chess robot broke the finger of a 7-year-old boy. Netizen: it violated the first law of robots
随机推荐
交换机和路由器技术-03-交换机基本配置
WebView basic use
信通院陈屹力:降本增效是云原生应用最大价值
二舅的外甥和他的学生们
Bit band operation of semaphore protection
Gartner authority predicts eight development trends of network security in the next four years
Behind every piece of information you collect, you can't live without TA
Xcode releases test package testflight
详解二叉树之堆
阿里巴巴鹰眼系统简介
MySQL: Functions
Technical practice dry goods | from workflow to workflow
The chess robot broke the finger of a 7-year-old boy. Netizen: it violated the first law of robots
How to extract tables from PDF through C /vb.net
深度学习能颠覆视频编解码吗?国家技术发明奖一等奖得主在小红书给你唠
Reference of meta data placeholder
Mobile end Foundation
SAP UI5 FileUploader 的本地文件上传技术实现分享
诸神黄昏,“猫抖快”告别大V时代
微软默默给 curl 捐赠一万美元,半年后才通知