2.8AC--PDD拼多多笔试4.10

第一题AC

思路是把数组从大到小排,或者图方便直接用从小到大快排,然后从大到小遍历,每3个跳过
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] nums = new int[n];
    for (int i = 0; i < n; i++) {
        nums[i] = sc.nextInt();
    }
    sc.close();
    Arrays.sort(nums);
    long res = 0;
    int curr = 0;
    for (int i = n - 1; i >= 0; i--) {
        curr++;
        if(curr % 3 == 0) continue;
        res = res + nums[i];
    }
    System.out.println(res);
}

第二题0.6

尝试了暴力、尝试了dp都超时/超空间
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] nums = new int[n];
    for (int i = 0; i < n; i++) {
        nums[i] = sc.nextInt();
    }
    sc.close();
    long res = 0;
    for (int i = 1; i <= n; i++) {
        long curr = 0;
        for (int j = 0; j < i; j++) {
            curr = curr + nums[j];
        }
        if(curr % m == 0) res = res + 1;
        for (int k = i; k < n; k++) {
            curr = curr - nums[k - i] + nums[k];
            curr = curr % m;
            if(curr == 0) res = res + 1;
        }
    }
    System.out.println(res);
}

第三题AC

牛客原题找靓号,前两天刚做过。。代码略

第四题0.2

毫无思路,直接返回了最多的数字
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] nums = new int[n];
    for (int i = 0; i < n; i++) {
        nums[i] = sc.nextInt();
    }
    sc.close();
    HashMap<Integer, Integer> blocks = new HashMap<>();
    for (int i = 0; i < n; i++) {
        if(blocks.containsKey(nums[i])) blocks.put(nums[i], blocks.get(nums[i]) + 1);
        else blocks.put(nums[i], 1);
    }
    int res = 0;
    for(Integer key : blocks.keySet()){
        if(blocks.get(key) > res) res = blocks.get(key);
    }
    System.out.println(res);
}
今天pdd的全靠第三题前两天做过,不然要被虐哭
#拼多多笔试##拼多多##笔试题目#
全部评论
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(),sum = 0; int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); for (int i = arr.length - 1,j = 1; i >= 0; i--,j++) { if (j % 3 != 0) { sum += arr[i]; } } System.out.println(sum); sc.close(); } 为什么我只有80%?
点赞 回复
分享
发布于 2020-04-10 21:09
求第三题代码或者思路😔
点赞 回复
分享
发布于 2020-04-10 21:13
滴滴
校招火热招聘中
官网直投
经历+1🤣
点赞 回复
分享
发布于 2020-04-10 21:14
AC 2.4第二题超时 10%
点赞 回复
分享
发布于 2020-04-10 21:16
AC2.3  第三题搜pdd原题的时候都搜到了但是没动手做 我就是个傻篮子
点赞 回复
分享
发布于 2020-04-10 21:23
第四题: lst=list(map(int,input().split(' '))) n=lst[0] k=lst[1] c=list(map(int,input().split(' '))) count0=0 for i in range(n):     count=1     j=i+1     while j<=n-1 and  c[j]==c[i]:         count=count+1         j=j+1     num=c[j:j+k].count(c[i])     count=count+num     j=j+k     while j<=n-1 and c[j]==c[i]:         count=count+1         j=j+1     if count0<count:         count0=count print(count0) 自我感觉思路还挺清晰的,40%不知为什么……有没有同学能解答一下呀~
点赞 回复
分享
发布于 2020-04-10 21:23
为什么我觉得这些笔试都好难啊,比leetcode hard还难,我太菜了
点赞 回复
分享
发布于 2020-04-10 21:25
2.9AC。 1 + 1 + 0.7 + 0.2。 第三题做太慢了,我tcl。
点赞 回复
分享
发布于 2020-04-10 21:39
来多多,做朋友
点赞 回复
分享
发布于 2020-04-10 23:48
lz拼多多有面试吗
点赞 回复
分享
发布于 2020-04-26 22:05

相关推荐

头像
03-18 09:09
Java
点赞 评论 收藏
转发
6 17 评论
分享
牛客网
牛客企业服务