首页 > 拼多多 拼越计划 服务端开发 笔经
头像
无情的offer收割机
编辑于 2020-08-28 18:22
+ 关注

拼多多 拼越计划 服务端开发 笔经

2020.08.02 晚上 笔试 2h

1)多多的骰子组合
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        if(k == 0) {
            System.out.println("paradox");
            return;
        }
        int n = sc.nextInt();
        int pos = k, cnt = 0, d;
        for(int i = 0; i < n; i++){
            d = sc.nextInt();
            if(d == pos) {
                if(i == n) {
                    pos = 0;
                }
                else {
                    System.out.println("paradox");
                    return;
                }
            } else if(d < pos) {
                pos -= d;
            } else {
                pos = d - pos;
                cnt++;
            }
        }
        System.out.println(pos + " " + cnt);
    }
}


2)多多吃饭

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int t = sc.nextInt();
        if(t == 0) {
            System.out.println(0);
            return;
        }
        int[][] a = new int[n][2];
        int[][] b = new int[m][2];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                b[i][j] = sc.nextInt();
            }
        }

        int res = Integer.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            if(a[i][1] >= t) {
                res = Math.min(res, a[i][0]);
                continue;
            }
            for (int j = 0; j < m; j++) {
                if(b[j][1] >= t) {
                    res = Math.min(res, b[j][0]);
                    continue;
                }
                if(a[i][1] + b[j][1] >= t) {
                    res = Math.min(res, a[i][0] + b[j][0]);
                }
            }
        }

        if(res == Integer.MAX_VALUE) {
            System.out.println(-1);
            return;
        }

        System.out.println(res);
    }
}


第一题100%,第三题50%,第二题不会做,第三题不会做,我好菜。

全部评论

(9) 回帖
加载中...
话题 回帖

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐