C. 思维 Pipes Codeforces Round #590 (Div. 3)

Codeforces Round #590 (Div. 3)
在这里插入图片描述

在这里插入图片描述

Example
inputCopy
6
7
2323216
1615124
1
3
4
2
13
24
2
12
34
3
536
345
2
46
54
outputCopy
YES
YES
YES
NO
YES
NO
Note
The first query from the example is described in the problem statement.


  • 很显然的是直的管只能横着放(无法衔接上下移动的方向接过来的管子)
  • 对于拐角管 如果之前是横着运动的 那么现在就得上移或者下移
  • 如果之前就是上下移动那么现在只可横着移动
  • now所在类 y所在行 dir前面的方向
#include<bits/stdc++.h>
using namespace std;
char s[2][200010];
int main()
{
	int tt;scanf("%d",&tt);
	while(tt--)
	{
		int n;scanf("%d",&n);
		scanf("%s%s",s[0],s[1]);
		int now=0,y=0,dir=0,f=0;
		while(now<n)
		{
			
			if(dir==0)//之前横 
			{
				if(s[y][now]=='1'||s[y][now]=='2')
				{
					now++;
				}else
			    {
			    	y=!y;
					dir=1; 
				}
			}else //之前竖着 
			{
				if(s[y][now]=='2'||s[y][now]=='1')
				{
					f=1;
					 break;
				}else 
				{
					dir=0;
					now++;
				}
			} 
		
		} 
	
		if(f||y==0)  puts("NO");
		else puts("YES");
	} 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值