米哈游笔试记录

1 括号匹配
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        StringBuilder buf = new StringBuilder();
        while(T-- > 0) {
            String s = sc.next();
            Stack<Character> stack = new Stack<>();
            int count = 0;
            for (int i = 0; i < s.length(); ++i) {
                if (stack.isEmpty() || s.charAt(i) == '[' || s.charAt(i) == '{') {
                    stack.add(s.charAt(i));
                } else {
                    if (s.charAt(i) == ']' && stack.peek() == '['
                            || stack.peek() == '{' && s.charAt(i) == '}') {

                    } else {
                        count++;
                    }
                    stack.pop();
                }
            }
            buf.append(count).append("\n");
        }
        System.out.print(buf);
    }
}
2 组合数学中的插板法
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        StringBuilder buf = new StringBuilder();
        while(T-- > 0) {  // 10^4
            int n = sc.nextInt() / 3;  // 10^5
            int count = (int)((long)(n-1)*(n-2) / 2);
            buf.append(count).append("\n");
        }
        System.out.print(buf);
    }
}
3 BFS
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r1 = sc.nextInt();
        int c1 = sc.nextInt();
        int r2 = sc.nextInt();
        int c2 = sc.nextInt();
        System.out.println(game(r1, c1, r2, c2));

    }

    public static int game(int r1, int c1, int r2, int c2) {
        if (r1 == r2 && c1 == c2) {
            return 0;
        }
        int[][] pos = new int[10][9];
        pos[r1][c1] = 1;
        Queue<Integer> que = new LinkedList<>();
        que.add(r1 * 10 + c1);
        int[][] dir = {{-3, -2}, {-2, -3}, {2, -3}, {3, -2},
                {3, 2}, {2, 3}, {-2, 3}, {-3, 2}};
        while (!que.isEmpty()) {
            int xy = que.remove();
            int x = xy / 10;
            int y = xy % 10;
            for (int i = 0; i < 8; ++i) {
                int xx = x + dir[i][0];
                int yy = y + dir[i][1];
                if (xx >= 0 && xx < 10 && yy >= 0 && yy < 9 && pos[xx][yy] == 0) {
                    if (xx == r2 && yy == c2) {
                        return pos[x][y];
                    }
                    int nextX = x + dir[i][0] / 3;
                    int nextY = y + dir[i][1] / 3;
                    if (nextX == r2 && nextY == c2) {
                        continue;
                    } else {
                        nextX = nextX + xx >> 1;
                        nextY = nextY + yy >> 1;
                        if (nextX == r2 && nextY == c2) {
                            continue;
                        }
                    }
                    pos[xx][yy] = pos[x][y] + 1;
                    que.add(xx * 10 + yy);
                }
            }
        }
        return -1;
    }
}



#米哈游##笔经#
全部评论
看不懂JAVA,可以解释一下第二题是什么意思吗, buf.append(count).append("\n");这句话不是拓展字符串吗?和最后的结果有什么关系
点赞 回复 分享
发布于 2021-09-13 08:32

相关推荐

投递小鹏汽车等公司7个岗位
点赞 评论 收藏
分享
Twilight_m...:表格简历有点难绷。说说个人看法: 1.个人基本情况里好多无意义信息,什么婚姻状况、健康状况、兴趣爱好、户口所在地、身份证号码、邮政编码,不知道的以为你填什么申请表呢。 2.校内实践个人认为对找工作几乎没帮助,建议换成和测开有关的项目,实在没得写留着也行。 3.工作经历完全看不出来是干什么的,起码看着和计算机没啥关系,建议加强描述,写点你在工作期间的实际产出、解决了什么问题。 4.个人简述大而空,看着像AI生成,感觉问题最大。“Python,C,C++成为我打造高效稳定服务的得力工具”、“我渴望凭借自身技术知识与创新能力,推动人工智能技术的应用发展,助力社会实现智能化转型”有种小学作文的美感。而且你确定你个人简述里写的你都会嘛?你AI这块写的什么“深入研究”,发几篇顶会的硕博生都不一定敢这么写。而且你AI这块的能力和软测也完全无关啊。个人简述建议写你对哪些技术栈、哪些语言、哪些生产工具的掌握,写的有条理些,而且最好是和测开强相关的。
点赞 评论 收藏
分享
07-17 12:09
门头沟学院 Java
讲的口干舌燥,头都晕了怎么要讲这么长啊
码农索隆:没事,你口干舌燥,他不一定会看,
投递小鹏汽车等公司7个岗位
点赞 评论 收藏
分享
评论
2
22
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务