美团8.13 后端方向笔试题 全AC

这题也太简单了。看脉脉上也说美团没多少HC。凉

魔法外卖

简单的模拟

public class Main
{
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        String[] line = cin.nextLine().split(" ");
        int n = Integer.parseInt(line[0]), t = Integer.parseInt(line[1]);
        int[] delivery = Arrays.stream(cin.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray();
        int count = 0, time = 0;
        Arrays.sort(delivery);
        for (int i = 0; i < n; i++) {
            if (time + t <= delivery[i]){
                time += t;
            } else {
                count++;
            }
        }
        System.out.printf("%d", count);
    }
}

打扫房间

简单模拟

public class Main
{
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        String[] line = cin.nextLine().split(" ");
        int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]), k = Integer.parseInt(line[2]);
        String orders = cin.nextLine();
        int[][] room = new int[n][m];
        room[0][0] = 1;
        int count = 1, x = 0, y = 0;
        for (int i = 0; i < orders.length(); i++) {
            char ch = orders.charAt(i);
            if (ch == 'W') x--;
            else if (ch == 'A') y--;
            else if (ch == 'S') x++;
            else y++;
            if (room[x][y] == 0) {
                room[x][y] = 1;
                count++;
            }
            if (count == n * m) {
                System.out.println("Yes");
                System.out.println(i + 1);
                return;
            }
        }
        System.out.println("No");
        System.out.println(n * m - count);
    }
}

扑克牌

用双向队列的 简单模拟
牌堆可以使用双向队列模拟。每轮从牌堆顶抽一张牌,再放入牌堆底。这个动作可以抽象为从队列头取出一个元素,再放入队尾。
我们使用origin数组模拟初始牌堆中每张牌的顺序和每张牌的牌点的关系。

public class Main
{
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        int n =  Integer.parseInt(cin.nextLine());
        int[] card = Arrays.stream(cin.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray();
        int[] origin = new int[n];
        Deque<Integer> d = new ArrayDeque<>();
        for (int i = 0; i < n; i++) d.offerLast(n - i - 1);
        for (int i = 0; i < n; i++) {
            d.offerFirst(d.pollLast());
            d.offerFirst(d.pollLast());
            origin[d.pollLast()] = card[i];
        }
        for (int i = 0; i < n; i++) {
            System.out.printf("%d ", origin[i]);
        }
    }
}

三元组

LeetCode经典3数之和改编版。唯一的坑是最后的三元组很多,用int会溢出。盲猜测试数据是全0。

public class Main
{
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        int n =  Integer.parseInt(cin.nextLine());
        int[] nums = Arrays.stream(cin.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray();
        long count = 0;
        Map<Integer, Integer> mp = new HashMap<>();
        mp.put(nums[n - 1], 1);
        for (int i = n - 2; i >= 1; i--) {
            for (int j = i - 1; j >= 0; j--) {
                count += mp.getOrDefault(3 * nums[i] - nums[j], 0);
            }
            mp.put(nums[i], mp.getOrDefault(nums[i], 0) + 1);
        }
        System.out.println(count);
    }
}

LeetCode经典 三角形最小路径。 不用care是不是叶子。因为叶子的累计的值一定比非叶子大。

public class Main
{
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        int n =  Integer.parseInt(cin.nextLine());
        String[] _nums = cin.nextLine().split(" ");
        int[] nums = new int[n + 1];
        for (int i = 1; i <= n; i++) nums[i] = Integer.parseInt(_nums[i - 1]);
        int ans = 0;
        Queue<Integer> q = new ArrayDeque<>();
        q.offer(1);
        while (!q.isEmpty()) {
            int t = q.poll();
            ans = Math.max(ans, nums[t]);
            if (2 * t <= n){
                nums[2 * t] += nums[t];
                q.offer(2 * t);
            }
            if (2 * t + 1 <= n) {
                nums[2 * t + 1] += nums[t];
                q.offer(2 * t + 1);
            }
        }
        System.out.println(ans);
    }
}
#美团##美团笔试##美团笔试题#
全部评论
草了,扑克牌那题想到约瑟夫环,然后就一直在推公式,搞半天忘记了暴力模拟这玩意了
14 回复 分享
发布于 2022-08-13 18:00
放个附加题更短的
4 回复 分享
发布于 2022-08-13 19:55
n, t = list(map(int, input().strip().split())) deadlines = list(map(int, input().strip().split())) cur = 0 ans = n for i in range(len(deadlines)):     if deadlines[i]>=cur+t:         ans-=1         cur+=t print(ans) 第一题我这样为啥不对啊😓
2 回复 分享
发布于 2022-08-13 18:06
怎么和还有个树的题?
2 回复 分享
发布于 2022-08-13 18:02
面试目前都是在陆续推进中,早笔试就可以早点获得面试机会哦~也祝同学秋招顺利~—————————————————————— 技术校招生们,如果还有其他关于求职的问题,那么你一定不能错过! 8月24日14:00-22:00,《美团请回答》特别节目“8小时不间断技术校招直播”,邀请美团8大技术方向通道委员+学长倾囊解惑!一次讲清楚所有技术方向,现场拆解笔面试,还有海量礼品相赠,欢迎来观看! 🟡方式一>>微信搜索【美团招聘】视频号,首页进直播 🟡方式二>>来B站直播间:http://live.bilibili.com/22355025 8小时岗位直播流程见:https://www.nowcoder.com/discuss/1019574,评论帖子HR在线回答哦
1 回复 分享
发布于 2022-08-18 17:17 北京
扑克单向队列模拟就行了,先push0到n-1的下标,跟着输入同时模拟,然后给ans数组对应的下标赋值就行
1 回复 分享
发布于 2022-08-14 09:37
双端队列模拟,好优雅的思路
1 回复 分享
发布于 2022-08-13 22:46
三元组那个,一直卡91%,int溢出真的是吐了。
1 回复 分享
发布于 2022-08-13 21:17
为啥我看了他得答案发现自己是个傻呗杯没这么简单,当时死活没想出来
1 回复 分享
发布于 2022-08-13 20:58
树那道是不是需要造树啊,我忘记咋造的了
1 回复 分享
发布于 2022-08-13 18:19
不懂就问,美团后端题全部是算法题吗?
点赞 回复 分享
发布于 2022-08-25 14:21 四川
大佬,有收到面试嘛?
点赞 回复 分享
发布于 2022-08-23 14:56 浙江
借楼 Z-Career核心岗位! 吉利集团、极氪汽车2023届校招内推来啦!! msx21DwJ 内推码如上!内推可以多增加3个岗位的投递,并且可以加快简历筛选! base杭州、上海、宁波杭州湾三地可选 极氪汽车是一家具有传统车企吉利背景的科技公司,致力于共创极致体验的出行生活!规划内的新车项目众多,未来可期! 2023届的师弟师妹们快快行动起来吧!有任何问题可留言或直接私信! 引流:吉利汽车 华为 蔚来 理想 小鹏 岚图 零跑 特斯拉 自动驾驶 智能驾驶 感知融合 规划控制 测试 路特斯 问界 极狐阿尔法 百度 金康赛力斯 长安 福特 威马 一汽 上汽 二汽 中国汽研 大陆 采埃孚ZF mobile eye 福瑞泰克 阿里 字节 momenta mmt 亚马逊 美团 拼多多pdd 小马智行 百度 阿波罗 Apollo 图森未来tusimple 余承东 #23届校招#
点赞 回复 分享
发布于 2022-08-17 22:52 浙江
大佬约面了吗
点赞 回复 分享
发布于 2022-08-17 18:48 北京
外企zoom校招内推   https://www.nowcoder.com/discuss/1016868
点赞 回复 分享
发布于 2022-08-16 11:53
大佬来试试华勤技术,内推码:NTAKLE0,详情可看帖子https://www.nowcoder.com/discuss/1016547
点赞 回复 分享
发布于 2022-08-16 11:43
去哪儿旅行校招开始咯,超多hc!PC端内推链接:https://app.mokahr.com/recommendation-apply/qunar/4208?recommendCode=NTANE0i#/jobs/?keyword=&_k=hjihl3
点赞 回复 分享
发布于 2022-08-15 16:31
为啥最后一题pythonDFS给我过个0
点赞 回复 分享
发布于 2022-08-15 16:12
https://www.nowcoder.com/discuss/1013764途虎内推哦
点赞 回复 分享
发布于 2022-08-14 19:15
有没有大佬知道怎么才能看自己的笔试成绩是否有效啊,交卷了才发现好像录屏没打开😅
点赞 回复 分享
发布于 2022-08-14 17:24

相关推荐

玉无心❤️:发照片干啥 发简历啊
点赞 评论 收藏
分享
03-13 10:35
安徽大学 Java
牛客246100688号:蚂蚁卡简历的,简历看不上眼全a了也不会有面试的。
投递蚂蚁集团等公司9个岗位
点赞 评论 收藏
分享
评论
43
211
分享

创作者周榜

更多
牛客网
牛客企业服务