滴滴笔试0904

滴滴笔试
9/4日第一题只过了73%,第二题A了

桃子装箱
public class MainDD01 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] one = br.readLine().split(" ");
        int n = Integer.parseInt(one[0]);
        int k = Integer.parseInt(one[1]);
        String[] taoZi = br.readLine().split(" ");
        int[] taoZiArr = new int[n];
        int allSum = 0;
        for (int i = 0; i < taoZi.length; i++) {
            taoZiArr[i] = Integer.parseInt(taoZi[i]);
            allSum += taoZiArr[i];
        }
        double allAvg = allSum * 1.0 / n;
        Arrays.sort(taoZiArr);
        int max = taoZiArr[n - 1];
        int ans = n;
        for(int i = n - 1; i > 0; i--){
            double tempAvg = allSum * 1.0 / (i + 1);
            if(taoZiArr[i] > tempAvg * k){
                allSum -= taoZiArr[i];
                ans--;
                continue;
            }
        }
        System.out.println(ans);
    }
}


// 魅力值
public class MainDD03 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] one = br.readLine().split(" ");
        String[] two = br.readLine().split(" ");
        String[] three = br.readLine().split(" ");
        int[] L = new int[one.length];
        int[] R = new int[two.length];
        int[] T = new int[three.length];
        for (int i = 0; i < one.length; i++) {
            L[i] = Integer.parseInt(one[i]);
        }
        for (int i = 0; i < two.length; i++) {
            R[i] = Integer.parseInt(two[i]);
        }
        for (int i = 0; i < three.length; i++) {
            T[i] = Integer.parseInt(three[i]);
        }
        for(int i = 0; i < n; i++){
            int ans = 0;
            for(int start = L[i]; start <= R[i]; start++){
                int t = getBeaute(start);
                if(t == T[i]) ans++;
            }
            System.out.print(ans + " ");
        }
    }
    // 计算魅力值
    public static int getBeaute(int i){
        int temp = i % 10;
        i /= 10;
        while(i > 0){
            temp ^= i % 10;
            i /= 10;
        }
        return temp;
    }
}


#滴滴笔试##秋招##滴滴23秋招笔试有点儿难啊#
全部评论
第二题我也这么写的 没a 超时了 过81%
1
送花
回复
分享
发布于 2022-09-05 02:03 福建
你这个第二题时间复杂度不对啊,暴力也能A?
点赞
送花
回复
分享
发布于 2022-09-04 23:35 湖南
滴滴
校招火热招聘中
官网直投
{"pureText":"","imgs":[{"alt":"discuss_166****579652.jpeg","height":1623,"localSrc":"content://media/external/images/media/138082","src":"https://uploadfiles.nowcoder.com/message_images/20220905/165664256_1662345579082/discuss_1662345579652.jpeg","width":960}]}
点赞
送花
回复
分享
发布于 2022-09-05 10:39 北京
这是我的摘桃子代码: ```java import java.util.*; public class Main{     public static void main(String args[]){         Scanner in = new Scanner(System.in);      int n = in.nextInt(), k = in.nextInt();         long[] nums = new long[n];         long sum = 0;         for (int i = 0; i < n; i++) {           nums[i] = in.nextLong();           sum += nums[i];         }         Arrays.sort(nums);         for (int i = n - 1; i >= 0; i--) {             if (nums[i] * (i + 1) <= sum * k) {                 System.out.println(i + 1);                 return;             } else {                 sum -= nums[i];             }         }     } } ```
点赞
送花
回复
分享
发布于 2022-09-05 14:42 湖南
hi~同学,秋招遇“寒气”,牛客送温暖啦!23届秋招笔面经有奖征集中,参与就得牛客会员7天免费体验,最高赢300元京东卡!戳我去看>>>https://www.nowcoder.com/link/zhengjipinglun
点赞
送花
回复
分享
发布于 2022-09-05 14:52 北京
请问滴滴笔试什么题型呢
点赞
送花
回复
分享
发布于 2022-09-16 17:03 辽宁

相关推荐

头像
不愿透露姓名的神秘牛友
04-02 21:36
点赞 评论 收藏
转发
3 9 评论
分享
牛客网
牛客企业服务