蔚来汽车提前批2022年7月13日

选择题

选择题有15道

  • 计算机网络网关
  • 递归
  • 概率计算
  • 哈希散列
  • 二叉树前序后序查找

编程题

编程题1-最大子方针

在这里插入图片描述

思路

直接使用暴力方法,从行列开始,方针的大小从2开始直到边界

代码

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n, m;
        n = in.nextInt();
        m = in.nextInt();
        int[][] nums = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                nums[i][j] = in.nextInt();
            }
        }

        int res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int len = 1; (i + len < n && j + len < m); len++) {
                    int temp = nums[i][j] + nums[i][j + len] + nums[i + len][j] + nums[i + len][j + len];
                    res = Math.max(res, temp);
                }
            }
        }
        System.out.println(res);

    }
}

在这里插入图片描述

测试案例只通过了这么一点点,不知道还有其他什么情况没有考虑到

编程题2-小红的乘法操作

在这里插入图片描述

思路

理解是求 b 和 a 的商,然后看这个商由x, y的多次乘法构成,先将商和x, y中最大的求商,直到商为1

代码

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x, y, a, b;

        x = in.nextInt();
        y = in.nextInt();
        a = in.nextInt();
        b = in.nextInt();

        int res = calcCnt(x, y, a, b);
        System.out.println(res);
    }

    public static int calcCnt(int x, int y, int a, int b) {
        if (b%a != 0)
            return -1;
        int cnt = 0, res = b/a;
        if (x > y) {
            int temp = x;
            y = x;
            x = y;
        }
        while (res != 1) {
            if (res % y == 0) {
                res /= y;
                cnt++;
            } else if (res % x == 0){
                res /= x;
                cnt++;
            } else {
                return -1;
            }
        }
        return cnt;
    }
}

在这里插入图片描述

还是没有通过所有测试案例,痛苦

编程题3-旅游

在这里插入图片描述

思路

遇到这种题还是只会暴力循环。。。这道题的通过测试案例更少,考虑问题的思路还是不够周到,这里的思路是:

  • 每次从一个城市开始,记录最大的花费和最小的花费
  • 添加其他城市的时候查看其他城市与当前最小花费和最大花费的差值是否大于k,大于k就不添加该城市,小于就添加
  • 然后查看每个城市开始的最大快乐值

代码

import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n, k;
        n = in.nextInt();
        k = in.nextInt();
        int[][] city = new int[n][2];

        for (int i = 0; i < n; i++) {
            city[i][0] = in.nextInt();
            city[i][1] = in.nextInt();
        }

        int max_happy = 0;
        for (int i = 0; i < n; i++) {
            int max_cost = city[i][0];
            int min_cost = city[i][0];
            int temp_happy = city[i][1];
            for (int j = 0; j < n; j++) {
                if (j != i) {
                    if (city[j][0] - min_cost < k && max_cost - city[j][0] < k) {
                        temp_happy += city[j][1];
                        min_cost = Math.min(min_cost, city[j][0]);
                        max_cost = Math.max(max_cost, city[j][0]);
                    }
                }
            }
            max_happy = Math.max(max_happy, temp_happy);
        }
        System.out.println(max_happy);


    }
}

在这里插入图片描述

提交之后才发现,第二次循环的起始条件应该是第一次循环指针i+1,这样可以避免重复计算城市的组合,还是太过粗心

笔试总结

蔚来的笔试总共90分钟,15到选择题,3道编程题,时间上还是比较宽裕的

  • 基础知识掌握不牢靠,选择题全靠猜,八股文需要好好再背一背
  • 编程题的思路有很大问题,关于动态规划的思路还是不能很快得出,需要再恶补一下动态规划的知识
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值