2017年第八届蓝桥杯省赛 Java A组
第一题
![截屏2021-04-03 15.34.07](https://tva1.sinaimg.cn/large/008eGmZEgy1gpbd0k8aooj30z40u0n2o.jpg)
import java.util.Arrays;
import java.util.Scanner;
public class Q1 {
static char[][] mp = new char[10][10];
static boolean[][] vis = new boolean[10][10];
static int ans = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
char[] temp = sc.next().toCharArray();
for (int j = 0; j < 10; j++) {
mp[i][j] = temp[j];
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (boolean[] v : vis)
Arrays.fill(v, false);
if (dfs(i, j))
ans++;
}
}
System.out.println(ans);
}
static boolean dfs(int x, int y) {
if (x < 0 || x >= 10 || y < 0 || y >= 10)
return true;
if (vis[x][y])
return false;
vis[x][y] = true;
switch (mp[x][y]) {
case 'L':
return dfs(x, y - 1);
case 'R':
return dfs(x, y + 1);
case 'U':
return dfs(x - 1, y);
case 'D':
return dfs(x + 1, y);
}
return false;
}
}
答案:31
第二题
![截屏2021-04-03 15.47.12](https://tva1.sinaimg.cn/large/008eGmZEgy1gpbczorsz9j318j0u041u.jpg)
import java.util.Arrays;
public class Q2 {
static int[] a = new int[15];
static boolean[] book = new boolean[15];
static int ans