Codeforces Round #590 (Div. 3) C. Pipes
思路:
因为管子可以旋转,所以实际上只有两种管子:有拐角的和直的而且非常显然直管子只能横着摆放,所以它的方向只能是向右而有拐角的管子在上一个管子的方向为向右的时候,它只能向上或者向下;在上一个管子的方向为上下的时候,它只能向右如果跑到最后管子在第一行,或者中间就卡死,就是没有摆放的方式;否则就是可以导通
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std
;
typedef long long ll
;
const int maxN
= 2e5 + 7;
const int maxM
= 2e6;
int n
;
char s
[2][maxN
];
int main()
{
int q
; scanf("%d", &q
);
while(q
-- )
{
scanf("%d", &n
);
for(int i
= 0; i
< 2; i
++ )
{
scanf("%s", s
[i
]);
}
int row
= 0, line
= 0, dir
= 0;
bool flag
= false;
while(line
< n
)
{
if(dir
== 0)
{
if(s
[row
][line
] <= '2')
{
line
++;
}
else
{
dir
= 1;
row
= !row
;
}
}
else
{
if(s
[row
][line
] <= '2')
{
flag
= true;
break;
}
else
{
dir
= 0;
line
++;
}
}
}
if(flag
|| row
== 0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
转载请注明原文地址: https://mac.8miu.com/read-488543.html