【笔试刷题】网易-2026.04.02-改编真题

✅ 春招备战指南 ✅

💡 学习建议:

  • 先尝试独立解题
  • 对照解析查漏补缺

🧸 题面描述背景等均已深度改编,做法和题目本质基本保持一致。

🍹 感谢各位朋友们的订阅,你们的支持是我们创作的最大动力

🌸 目前本专栏已经上线200+套真题改编解析,后续会持续更新的

春秋招笔试机考招合集 -> 互联网必备刷题宝典🔗

网易-2026.04.02

题目一:边境排阵

看起来是田忌赛马换皮,本质就是“最多能赢几场”。把双方战力排序后,用最小可行的己方单位去吃掉当前最弱的对手,最后检查最大胜场是否严格超过一半。

难度:Low

题目二:背包格整理

先按题目给的三层关键字排序,再把每个物品按“行优先、列次之”的规则塞进网格。难点不在算法,而在把放置规则翻译成稳定的逐格扫描。

难度:Mid

题目三:索桥火炮清场

真正的关键不是模拟每一炮,而是反过来问:打了 炮之后,哪些坐标组无论怎么推都不可能被边界淘汰。那些还卡在中间的坐标组只能靠直接命中解决,于是可以二分答案。

难度:Mid

题目四:贴图驻留调度

整题就是按规则做状态机。只要先看透“同一贴图当前已加载 mip 始终是一段连续后缀,且过期时间一致”,实现就能收敛到按贴图维护 minMip + expire + usedVRAM 的模拟。

难度:High

1. 边境排阵

问题描述

边境演练开始后,对手已经提前公开了这一轮的出阵顺序。

一共会进行 轮对抗。第 轮里,对手会派出一支战力为 的小队。你手里也有 支小队,它们的战力分别是 ,并且每支小队只能出战一次。

每轮规则如下:

  • 如果你派出的小队战力严格大于对手,这一轮记为你方获胜。
  • 如果双方战力相同,或者你方更小,都算你方失利。

你可以自由安排己方 支小队的出战顺序。请判断,是否存在一种安排方式,使得最终你方的胜场数严格大于败场数。

保证 是奇数。

输入格式

第一行输入一个整数 ,表示测试数据组数。

对于每组数据:

  • 第一行输入一个奇数 ,表示双方小队数量。
  • 第二行输入 个整数 ,表示己方小队战力。
  • 第三行输入 个整数 ,表示对手按出战顺序给出的战力。

输出格式

对于每组数据输出一行:

  • 若可以做到胜场数严格大于败场数,输出 YES
  • 否则输出 NO

样例输入

2
5
2 5 7 1 6
3 5 6 2 7
3
3 3 3
3 3 3

样例输出

YES
NO

数据范围

  • 为奇数
  • 所有测试数据中, 的总和不超过
样例 解释说明
样例 1 第一组可以把己方战力排成一种更优的对位方式,最终拿到超过一半的胜场,所以输出 YES。第二组所有人战力都相同,而平局也算失利,因此不可能赢过对手。

题解

题目真正要问的是:己方最多能赢多少场。

只要最大胜场数都不超过 ,那就不可能让胜场严格大于败场;反过来,如果最大胜场数大于 ,答案就是 YES

所以核心只剩一句话:

  • 怎么求“最多能赢几场”。

这就是标准的贪心配对。

先把己方战力数组和对手战力数组都从小到大排序。随后用一个指针 j 指向当前还没有被击败的最弱对手:

  • 依次查看排好序的己方战力 a
  • 如果当前这支队伍 a[i] 能击败 b[j],就让它去拿下这一分,然后 j 往后移动。
  • 如果 a[i] 连当前最弱的 b[j] 都打不过,那么它拿去对别的对手也不会更好,直接放弃这支队伍,继续看下一支更强的己方队伍。

为什么这个贪心是对的?

  • 如果某支己方队伍已经可以赢下当前最弱的可击败对手,那就没有必要把它浪费到更强的对手身上。
  • 让它吃掉当前最弱的那一个,能把更强的己方队伍留给后面更难啃的对手。
  • 如果它连当前最弱的都赢不了,那它无论换谁都不可能拿分,跳过不会损失最优解。

因此,这个过程统计出来的胜场数就是最大胜场数。

最后因为 是奇数,所以“胜场严格大于败场”恰好等价于:

直接判断即可。

复杂度分析

  • 排序复杂度是
  • 双指针线性扫描复杂度是

所以单组数据总复杂度为 ,空间复杂度为 。在所有测试数据总规模不超过 的条件下完全可以通过。

参考代码

  • Python
import sys

input = lambda: sys.stdin.readline().strip()


def max_win(a, b):
    # 排序后,始终尝试用当前最小的可行己方战力去击败最弱的未击败对手。
    a.sort()
    b.sort()

    j = 0
    win = 0
    n = len(a)

    for x in a:
        # 只有严格大于时才算获胜。
        if j < n and x > b[j]:
            win += 1
            j += 1

    return win


def solve():
    t = int(input())
    out = []

    for _ in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        b = list(map(int, input().split()))
        win = max_win(a, b)
        out.append("YES" if win > n // 2 else "NO")

    sys.stdout.write("\n".join(out))


if __name__ == "__main__":
    solve()
  • Cpp
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int maxWin(vector<long long>& a, vector<long long>& b) {
    // 贪心原则:用最小的可行己方战力去吃掉当前最弱的可击败对手。
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int n = static_cast<int>(a.size());
    int j = 0;
    int win = 0;

    for (long long x : a) {
        if (j < n && x > b[j]) {
            ++win;
            ++j;
        }
    }

    return win;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;

        vector<long long> a(n), b(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        for (int i = 0; i < n; ++i) {
            cin >> b[i];
        }

        int win = maxWin(a, b);
        cout << (win > n / 2 ? "YES" : "NO") << '\n';
    }
    return 0;
}
  • Java
import java.io.InputStream;
import java.util.Arrays;

public class Main {
    private static int maxWin(long[] a, long[] b) {
        // 先排序,再做一次双指针统计最大胜场。
        Arrays.sort(a);
        Arrays.sort(b);

        int j = 0;
        int win = 0;
        int n = a.length;

        for (long x : a) {
            if (j < n && x > b[j]) {
                win++;
                j++;
            }
        }
        return win;
    }

    public static void main(String[] args) throws Exception {
        FastScanner fs = new FastScanner(System.in);
        StringBuilder sb = new StringBuilder();

        int t = fs.nextInt();
        while (t-- > 0) {
            int n = fs.nextInt();
            long[] a = new long[n];
            long[] b = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = fs.nextLong();
            }
            for (int i = 0; i < n; i++) {
                b[i] = fs.nextLong();
            }

            int win = maxWin(a, b);
            sb.append(win > n / 2 ? "YES" : "NO").append('\n');
        }

        System.out.print(sb);
    }

    private static class FastScanner {
        private final InputStream in;
        private final byte[] buf = new byte[1 << 16];
        private int ptr = 0;
        private int len = 0;

        FastScanner(InputStream is) {
            in = is;
        }

        private int read() throws Exception {
            if (ptr >= len) {
                len = in.read(buf);
                ptr = 0;
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[ptr++];
        }

        long nextLong() throws Exception {
            int c;
            do {
                c = read();
            } while (c <= 32);

            long sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }

            long val = 0;
            while (c > 32) {
                val = val * 10 + (c - '0');
                c = read();
            }
            return val * sign;
        }

        int nextInt() throws Exception {
            return (int) nextLong();
        }
    }
}

2. 背包格整理

问题描述

小基 在整理一个带网格的仓库背包。

背包一共有 列,行号从上到下递增,列号从左到右递增。现在有 个物品,需要先按固定规则排序,再按顺序依次尝试放入背包。

每个物品都有下面这些属性:

  • id:物品唯一编号,所有物品的 id 互不相同。
  • heightwidth:物品占用的高和宽,不能旋转。
  • quality:品质,数值越大越优先。
  • type:类别,只会是 equipweaponitemother 之一。

排序规则如下:

  1. 先按 type 排序,优先级为 equip > weapon > item > other
  2. type 相同,则 quality 更高的排在前面。
  3. 若前两项都相同,则 id 更小的排在前面。

放置规则如下:

  • 按排好序后的顺序,一个一个尝试放入背包。
  • 对于当前物品,优先选择行号最小的可行位置;如果同一行里有多个可行位置,再选列号最小的那个。
  • 物品必须完整放进背包,且覆盖区域内所有格子都还为空。
  • 如果整个背包都找不到可行位置,就跳过这个物品。

请输出:

  1. 最终是否放下了全部物品。
  2. 最终背包每个格子里放的是哪个物品的 id;若为空则输出 0

输入格式

第一行输入三个整数 ,分别表示背包的高、宽和物品数量。

接下来 行,每行输入:

id height width quality type

其中 type 只会是 equipweaponitemother 之一。

输出格式

第一行输出一个字符串:

  • 如果所有物品都成功放入,输出 YES
  • 否则输出 NO

接下来输出 行,每行 个整数,表示最终背包状态。

样例输入

4 3 3
1 1 3 7 other
2 3 1 2 equip
3 2 2 4 other

样例输出

YES
2 3 3
2 3 3
2 0 0
1 1 1

数据范围

  • type 只会在 equipweaponitemother 中出现
样例 解释说明
样例 1 排序后,id=2 的装备会最先放入;随后在剩余空位中继续尝试放 id=3id=1,最终三个物品都能放下,所以输出 YES

题解

这题没有隐藏算法,按题意一步一步模拟就够了。

先做排序。

题目已经给出了三层比较关键字:

  1. type 优先级。
  2. quality 降序。
  3. id 升序。

把每个物品存下来以后,按这个规则排一次序即可。

然后是放置。

对于当前物品,题目要求:

  • 行号尽量小。
  • 在满足这个前提下,列号尽量小。

这句话直接翻译成程序,就是枚举左上角坐标 (r,c)

  • r 从上到下扫。
  • c 在当前行里从左到右扫。
  • 一旦找到一个可以完整放下的位置,就立刻放进去,不必继续找。

判断一个位置能不能放也很直接:

  • 先看物品右边界和下边界会不会越出背包。
  • 再检查这个 height × width 矩形里的格子是否全是空格。

如果找到位置,就把这个矩形区域全部写成对应的 id;如果遍历完整个背包都找不到,就说明这个物品放不进去。

最后再看是否所有物品都成功放入:

  • 全部成功则输出 YES
  • 只要有一个被跳过,就是 NO

复杂度分析

设单个物品大小为

  • 排序复杂度是
  • 每个物品最多尝试所有左上角位置,共 个。
  • 每次检查位置需要看 个格子,而题目保证 ,这是一个很小的常数。

所以总复杂度可以写成 。在本题范围内完全足够,空间复杂度为

参考代码

  • Python
import sys

input = lambda: sys.stdin.readline().strip()

PRI = {
    "equip": 3,
    "weapon": 2,
    "item": 1,
    "other": 0,
}


def can_put(grid, r, c, h, w):
    # 只要矩形里出现一个非 0 格子,这个位置就不能放。
    for i in range(r, r + h):
        for j in range(c, c + w):
            if grid[i][j] != 0:
                return False
    return True


def put_item(grid, r, c, h, w, item_id):
    # 找到可行位置后,把整个占用矩形统一写成当前物品 id。
    for i in range(r, r + h):
        for j in range(c, c + w):
            grid[i][j] = item_id


def solve():
    n, m, t = map(int, input().split())
    items = []

    for _ in range(t):
        item_id, h, w, q, typ = input().split()
        items.append((int(item_id), int(h), int(w), int(q), typ))

    # 先按题目给定规则排序。
    items.sort(key=lambda x: (-PRI[x[4]], -x[3], x[0]))

    grid = [[0] * m for _ in range(n)]
    ok = True

    for item_id, h, w, _, _ in items:
        placed = False

        for r in range(n - h + 1):
            for c in range(m - w + 1):
                if can_put(grid, r, c, h, w):
                    put_item(grid, r, c, h, w, item_id)
                    placed = True
                    break
            if placed:
                break

        if not placed:
            ok = False

    print("YES" if ok else "NO")
    for row in grid:
        print(*row)


if __name__ == "__main__":
    solve()
  • Cpp
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Item {
    int id;
    int h;
    int w;
    int q;
    string type;
};

int typePriority(const string& type) {
    if (type == "equip") {
        return 3;
    }
    if (type == "weapon") {
        return 2;
    }
    if (type == "item") {
        return 1;
    }
    return 0;
}

bool canPut(const vector<vector<int>>& grid, int r, int c, int h, int w) {
    for (int i = r; i < r + h; ++i) {
        for (int j = c; j < c + w; ++j) {
            if (grid[i][j] != 0) {
                return false;
            }
        }
    }
    return true;
}

void putItem(vector<vector<int>>& grid, int r, int c, int h, int w, int id) {
    for (int i = r; i < r + h; ++i) {
        for (int j = c; j < c + w; ++j) {
            grid[i][j] = id;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, t;
    cin >> n >> m >> t;

    vector<Item> items(t);
    for (int i = 0; i < t; ++i) {
        cin >> items[i].id >> items[i].h >> items[i].w >> items[i].q >> items[i].type;
    }

    sort(items.begin(), items.end(), [](const Item& a, const Item& b) {
        int pa = typePriority(a.type);
        int pb = typePriority(b.type);
        if (pa != pb) {
            return pa > pb;
        }
        if (a.q != b.q) {
            return a.q > b.q;
        }
        return a.id < b.id;
    });

    vector<vector<int>> grid(n, vector<int>(m, 0));
    bool ok = true;

    for (const Item& item : items) {
        bool placed = false;

        for (int r = 0; r + item.h <= n && !placed; ++r) {
            for (int c = 0; c + item.w <= m; ++c) {
                if (canPut(grid, r, c, item.h, item.w)) {
                    putItem(grid, r, c, item.h, item.w, item.id);
                    placed = true;
                    break;
                }
            }
        }

        if (!placed) {
            ok = false;
        }
    }

    cout << (ok ? "YES" : "NO") << '\n';
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (j) {
                cout << ' ';
            }
            cout << grid[i][j];
        }
        cout << '\n';
    }
    return 0;
}
  • Java
import java.io.InputStream;
import java.util.Arrays;

public class Main {
    private static class Item {
        int id;
        int h;
        int w;
        int q;
        String type;
    }

    private static int typePriority(String type) {
        if ("equip".equals(type)) {
            return 3;
        }
        if ("weapon".equals(type)) {
            return 2;
        }
        if ("item".equals(type)) {
            return 1;
        }
        return 0;
    }

    private static boolean canPut(int[][] grid, int r, int c, int h, int w) {
        for (int i = r; i < r + h; i++) {
            for (int j = c; j < c + w; j++) {
                if (grid[i][j] != 0) {
                    return false;
                }
            }
        }
        return true;
    }

    private static void putItem(int[][] grid, int r, int c, int h, int w, int id) {
        for (int i = r; i < r + h; i++) {
            for (int j = c; j < c + w; j++) {
                grid[i][j] = id;
            }
        }
    }

    public static void main(String[] args) throws Exception {
        FastScanner fs = new FastScanner(System.in);

        int n = fs.nextInt();
        int m = fs.nextInt();
        int t = fs.nextInt();

        Item[] items = new Item[t];
        for (int i = 0; i < t; i++) {
            Item item = new Item();
            item.id = fs.nextInt();
            item.h = fs.nextInt();
            item.w = fs.nextInt();
            item.q = fs.nextInt();
            item.type = fs.next();
            items[i] = item;
        }

        Arrays.sort(items, (a, b) -> {
            int pa = typePriority(a.type);
            int pb = typePriority(b.type);
            if (pa != pb) {
                return pb - pa;
            }
            if (a.q != b.q) {
                return b.q - a.q;
            }
            return a.id - b.id;
        });

        int[][] grid = new int[n][m];
        boolean ok = true;

        for (Item item : items) {
            boolean placed = false;

            for (int r = 0; r + item.h <= n && !placed; r++) {
                for (int c = 0; c + item.w <= m; c++) {
                    if (canPut(grid, r, c, item.h, item.w)) {
                        putItem(grid, r, c, item.h, item.w, item.id);
                        placed = true;
                        break;
                    }
                }
            }

            if (!placed) {
                ok = false;
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(ok ? "YES" : "NO").append('\n');
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (j > 0) {
                    sb.append(' ');
                }
                sb.append(grid[i][j]);
            }
            sb.append('\n');
        }

        System.out.print(sb);
    }

    private static class FastScanner {
        private final InputStream in;
        private final byte[] buf = new byte[1 << 16];
        private int ptr = 0;
        private int len = 0;

        FastScanner(InputStream is) {
            in = is;
        }

        private int read() throws Exception {
            if (ptr >= len) {
                len = in.read(buf);
                ptr = 0;
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[ptr++];
        }

        String next() throws Exception {
            int c;
            do {
                c = read();
            } while (c <= 32);

            StringBuilder sb = new StringBuilder();
            while (c > 32) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        long nextLong() throws Exception {
            int c;
            do {
                c = read();
            } while (c <= 32);

            long sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }

            long val = 0;
            while (c > 32) {
                val = val * 10 + (c - '0');
                c = read();
            }
            return val * sign;
 

剩余60%内容,订阅专栏后可继续查看/也可单篇购买

互联网刷题笔试宝典 文章被收录于专栏

互联网刷题笔试宝典,这里涵盖了市面上大部分的笔试题合集,希望助大家春秋招一臂之力

全部评论

相关推荐

03-28 08:35
已编辑
浙江大学 Java
好焦虑。&nbsp;来jd三周了第一周三天培训,两天熟悉项目技术。第二周熟悉项目框架业务。第三周也就是这一周,做了一个从数据库提数进行业务计算的活,前两天在写sql,后两天在折腾低代码工作流。虽然这个低代码工作流是我提出的,因为纯sql太复杂了,不好排查问题。下周要做的也就是一些小需求,虽然我看同期排班其他正职的活看上去也没多核心。之前还担心会做一些不是很后端的而偏ai的,网上又说纯后端好。但是这些天下来,组里里面也都是Java后端,我倒是又想学一些偏ai的东西。组里有ai的感觉最多就是调接口。工作流是平台的低代码dify类似的,拉拉模块写写js、python脚本。这种体量公司,mcp都一键化了,写个Java接口秒变mcp,都用不着自己写。这周折腾sql和调低代码工作流,耗费心力,没什么技术含量,就靠时间磨。这周SQL确实精进了不少,从只会增删改查(甚至不熟练),到现在能看懂、能写复杂语句,可这点进步根本压不住心里的焦虑。低代码工作流这种东西,谁来上手都能会,毫无技术壁垒可言。今天跟产品沟通,她早就玩得比我熟练,还反过来教我看工作流日志,女朋友在产品实习,平时也用低代码工作流。越想越觉得压抑,一周下来,除了SQL,其他全是原地踏步。工作流节点一多平台就卡到崩溃,跟问AI等半天、报错反复改再等半天一样,磨人心志。搞这些真的很好费时间,不能好好学想学的东西。心里有点想学python那些agent应用开发,感觉是趋势,又判断不清后端的路是否还是很有前景。同时又想着骑驴找马,想准备八股算法去其他公司。还要包装产出。实在是迷茫往哪个方向准备。我想四月中旬开始投暑期。我不是很想留北京,我想回杭州或者上海。南方人在北京生活不习惯,没有归属感。求职好难,找个工作好难。
淘气煲条妈妈:加油老哥,我过两周也来 jd 了
点赞 评论 收藏
分享
最近好多人问我这个问题,我自己也是纠结过很久,现在秋招春招走下来,多少有点感触了,写出来给大家参考参考。先说结论:没有绝对的好坏,取决于你处在哪个阶段、手里有什么牌、以及你缺什么。📌大厂实习优点很明显,大厂的title确实好用,简历关会好过很多,面试的时候面试官也更容易认可你的经历,毕竟流程规范、业务体量大,哪怕你干的活再边缘,说出去也是有背书效果的。而且大厂的实习流程相对成熟,mentor制度、内部文档这些都比较全,对第一次实习的人来说,能快速建立对流程工作的认识。不过缺点也存在,很多时候大厂实习生干的活真的很碎,可能会在大厂实习三个月,每天就是导数据、做周报、跟会议纪要,项目都没摸全。还有就是转正这件事,现在大厂hc锁得厉害,暑期实习转正都不一定稳,更别说日常实习了~📌小厂实习小厂的好处是你能接触到的东西更杂更全,我有一段中厂的经历,虽然公司不大,但因为人手少,我从运营到产品甚至商务都掺和过,面试的时候聊起来反而有很多可以讲的,因为真的亲手做了落地的东西。而且小厂的氛围通常更灵活,mentor可能就是直接带你的人,关系更近,学东西也更直接。缺点就是title确实吃亏,我投简历的时候明显感觉到,有些大厂筛简历就是看学校+实习公司名字,小厂经历有时候直接被忽略。还有就是小厂的流程不规范,有的公司去了就是自己摸索,没人带,成长全靠自己踩坑,体验差别很大。📌我自己的感受我三段实习里,有大厂也有中小厂,现在回头看,这样安排还不错:第一段实习可以去小厂,快速上手、积累能落地的项目经验;第二段争取去大厂,拿个title,看看规范化的工作流程;第三段,那就看自己缺什么,想转正就找有hc的,想刷简历就继续冲大厂。我发现面试官其实更在意的是你在实习里到底做了什么、有没有自己的思考,而不是单纯看公司名字。大厂经历是敲门砖,但聊得深了,还是看你有没有真东西。小厂经历只要你能讲清楚做了什么、解决了什么问题、有什么复盘,反而更容易出彩。最后想说,不管大厂小厂,能让你有成长、能给你空间去试错、能让你在面试时有东西可讲的,就是好厂。别太纠结,有offer先接着,实在不满意再骑驴找马,总比干等着强!
大厂实习和小厂实习最大的...
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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