用我可怜的提前批笔试经历来攒人品之蔚来提前批笔试(二)
这次题真的很舒适,选择题也出的很合理,厉害点的同学几乎都可以拿满分,但是因为前面选择花的时间长等原因最后一个题交卷两分钟之后才写完,蔚来估计是无缘了,希望今年能找到心仪的工作(拜托)
1. 给你一大一小俩矩阵,判断小的矩阵是否为大矩阵的子矩阵,(无坑直接弱智暴力100%
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int Kase = scanner.nextInt();
while(Kase > 0){
Kase--;
int m = scanner.nextInt();
int n = scanner.nextInt();
char[][] big = new char[m][m];
char[][] small = new char[n][n];
scanner.nextLine();
for(int i=0;i<m;i++){
String line = scanner.nextLine();
big[i] = line.toCharArray();
}
for(int j = 0; j<n; j++){
String line = scanner.nextLine();
small[j] = line.toCharArray();
}
boolean find = false;
for(int i=0; i<= m-n && !find; i++){
for(int j = 0; j <= m-n; j++){
boolean flag = false;
int count = 0;
for(int k = 0; k<n && !flag; k++){
for(int p = 0; p<n ; p++){
if(big[i+k][j+p] != small[k][p]){
flag = true;
break;
}
count++;
}
}
if(count == n*n){
System.out.println("Yes");
find = true;
break;
}
}
}
if(!find){
System.out.println("No");
}
}
}
} 2. 给定一个由小括号组成的字符串,求合法的前缀数量,什么意思呢,(())),合法前缀是4,()()(())合法前缀是8,)()()合法前缀是0(此处有点记不清了大概是这个意思吧,也可能理解错了所以有百分之30没过)
import java.util.*;
public class Main2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
char[] quote = scanner.nextLine().toCharArray();
int index = 0;
Stack<Character> stack = new Stack<>();
stack.push(quote[index++]);
int ans = 0;
//代码写的很丑,见谅
while(index < n){
if(!stack.isEmpty()){
if(stack.peek()=='(' && quote[index] == ')'){
stack.pop();
index++;
ans += 2;
}else{
stack.push(quote[index++]);
}
}else{
//stack 为空 但是此时的下一个字符是')' 此时已经非法
if(quote[index] == ')'){
break;
}else{
stack.push(quote[index++]);
}
}
}
System.out.println(ans);
}
} 3. 一个小孩家在(1,1)位置,学校在(1,1)位置,路上有两个点井盖被盗了,问你从学校到家有多少条路,答案要mod 998244353。(用dfs简单写了一下但是不知道对不对,可能会超时吧
import java.util.*;
public class Main3 {
public static int n;
public static int[][] map;
public static boolean[][] vis;
public static int ans;
public static final int MOD = 998244353;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
map = new int[n][n];
vis = new boolean[n][n];
ans = 0;
int[] t1 = new int[]{scanner.nextInt()-1,scanner.nextInt()-1};
int[] t2 = new int[]{scanner.nextInt()-1,scanner.nextInt()-1};
map[t1[0]][t1[1]] = -1;
map[t2[0]][t2[1]] = -1;
dfs(0,0);
System.out.println(ans);
}
public static void dfs(int x, int y){
if(x >= n || y >= n){
return;
}
// 绕开井盖
if(map[x][y] == -1){
return;
}
if(!vis[x][y]){
vis[x][y] = true;
}
if(x == n-1 && y == n-1){
ans++;
ans = ans % MOD;
vis[x][y] = false;
return;
}
//向右下方探索即可
dfs(x, y+1);
dfs(x+1,y);
vis[x][y] = false;
}
}都笔试完了吧,还在笔试的看见给我退出去(叉腰
#蔚来提前批笔试#