模拟DFS 迷宫 2017蓝桥杯A组A题
作者:
徐枭翔
,
2024-03-21 21:01:50
,
所有人可见
,
阅读 6
https://www.lanqiao.cn/problems/641/learning/?page=1&first_category_id=1&second_category_id=3&name=%E8%BF%B7%E5%AE%AB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define pb(i) push_back(i)
#define int long long
#define INF 0x3f3f3f3f
#define oz 998244353
#define endl '\n'
#define N 200010
const int mod = 1e9 + 7;
int p[N], si[N];
int find(int x) {
if (x != p[x]) p[x] = find(p[x]);
return p[x];
}
//size[find(b)] += size[find(a)];
//p[find(a)] = find(b);
char s[15][15];
int st[15][15];
int res;
void solve() {
rep(i, 1, 10) {
rep(j, 1, 10)
cin >> s[i][j];
}
rep(i, 1, 10) {
rep(j, 1, 10) {
int x = i, y = j;
memset(st, 0, sizeof st);
while (!st[x][y]) {
st[x][y] = 1;
if (s[x][y] == 'U')x --;
else if (s[x][y] == 'D')x ++;
else if (s[x][y] == 'L')y --;
else y ++;
if (x < 1 || x > 10 || y < 1 || y > 10) {
res ++;
break;
}
}
}
}
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
solve();
return 0;
}