-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathA_Computer_Game.cpp
153 lines (149 loc) · 3.5 KB
/
A_Computer_Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <bits/stdc++.h>
using namespace std;
//----------------------------------------------------------------//
// definitions //
#define endl '\n'
#define PI (acos(-1.0))
#define tan(a) tan(a) / (PI / 180)
#define sin(a) sin(a) / (PI / 180)
#define cos(a) cos(a) / (PI / 180)
//----------------------------------------------------------------//
// data types//
struct Point
{
float x, y;
};
//----------------------------------------------------------------//
// preDefined functions//
// geometry//
double getClockwiseAngle(Point p)
{
double angle = 0.0;
angle = -1 * atan2(p.x, -1 * p.y);
return angle;
}
bool comparePoints(Point p1, Point p2) { return getClockwiseAngle(p1) < getClockwiseAngle(p2); }
double polygonArea(vector<Point> &points)
{
double area = 0.0;
long long j = points.size() - 1;
for (long long i = 0; i < points.size(); i++)
{
area += (points[j].x + points[i].x) * (points[j].y - points[i].y);
j = i;
}
return abs(area / 2.0);
}
// geometry//
// number theory //
template <typename T>
long long factorial(T N)
{
long long ans = 1;
while (N > 1)
ans *= N--;
return ans;
}
template <typename T, typename Y>
long long NCR(T N, Y R)
{
long long ans = 1, tmp = N - R;
while (N > 1)
{
ans *= N--;
while (R > 1 and !(ans % R))
ans /= R--;
while (tmp > 1 and !(ans % tmp))
ans /= tmp--;
}
return ans;
}
template <typename T, typename Y>
long long NPR(T N, Y R)
{
long long ans = 1, tmp = N - R;
while (N > 1)
{
ans *= N--;
while (tmp > 1 and !(ans % tmp))
ans /= tmp--;
}
return ans;
}
void sieve(vector<bool> &ans)
{
ans[0] = ans[1] = false;
long long tmp = sqrt(ans.size()), till = ans.size();
for (long long i = 2; i <= tmp; i++)
if (ans[i])
for (long long j = i * i; j < till; j += i)
ans[j] = false;
}
template <typename T>
map<long long, long long> primeFactors(T N)
{
map<long long, long long> ans;
long long till = sqrt(N);
for (long long i = 2; i <= till; i++)
{
while (!(N % i))
{
ans[i]++;
N /= i;
}
if (i >= N or i >= till)
break;
}
if (N > 1)
ans[N]++;
return ans;
}
// number theory//
bool isVowel(char c)
{
string vowel = "aeiouAEIOU";
for (auto &it : vowel)
if (it == c)
return true;
return false;
}
//----------------------------------------------------------------//
// helper functions //
long long n;
char grid[2][111];
bool depthFirstSearch(int row, int column)
{
if(column==n-1 and grid[1][column]=='0')return true;
if (grid[0][column + 1] == '0' and column < n)
return (depthFirstSearch(0, column + 1));
if(grid[1][column + 1] == '0' and column < n)
return( depthFirstSearch(1, column + 1));
return false;
}
//----------------------------------------------------------------//
// solve function//
void solve()
{
cin >> n;
for (long long i = 0; i < 2; i++)
for (long long j = 0; j < n; j++)
cin >> grid[i][j];
if (depthFirstSearch(0, 0) and grid[0][0] == '0')
cout << "YES" << endl;
else
cout << "NO" << endl;
}
//----------------------------------------------------------------//
// main function//
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long test = 1;
cin >> test;
while (test--)
{
solve();
}
}