百度笔试-有大佬知道第三题和第一题咋做吗,第一题一直60%

百度笔试-有大佬知道第三题和第一题咋做吗,第一题一直60%

public class Test1 { public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);  int n=sc.nextInt();  int m=sc.nextInt();  int[] arr=new int[2*n];
        List<Integer> list=new ArrayList<>(); int num=0;  for(int i=0;i<n*2;i++){
            arr[i]=sc.nextInt(); if (i%2==1){ if (arr[i-1]>m){
                    num+=arr[i];
                }else { for (int j=0;j<arr[i];j++){
                        list.add(arr[i-1]);
                    }
                }
            }
        }
        Collections.sort(list); int start=0;  int end=list.size()-1; while (end>=start){  int temp=list.get(end--);  if(temp>=m){
                num++;
            }else {
                temp+=list.get(start++); while (temp<m&&start<=end){
                    temp+=list.get(start++);
                }
                num++;
            }
        }
        System.out.println(num);
    }
}

public class Test2 { static int sum; public static void main(String[] args) {
        Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); sum=procee(n,k);
        System.out.println(sum);
    } private static int procee(int n, int k) { int small=getSum(n,k); if (small==-1){ return 1;
        }else { int big=small+k; sum=procee(small,k)+procee(big,k);
        } return sum;
    } private static int getSum(int n, int k) { int temp=n-k; if (temp<=1){ return -1;
       }else { if (temp%2==0){ return temp/2;
           }else { return -1;
           }
       }
    }
}
第三题不会啊
#笔试题目##百度#
全部评论
第三题是摆火柴吗?后面有帖子,用的dp
点赞 回复 分享
发布于 2019-09-10 21:37
第三题删除叶子节点?
点赞 回复 分享
发布于 2019-09-10 21:12
第三题样例都能过,一交0%😥
点赞 回复 分享
发布于 2019-09-10 21:07

相关推荐

07-09 20:50
门头沟学院 Java
码农索隆:1.教育背景和荣誉证书合二为一。 2.获奖项目理一遍,你做了什么,对你求职的岗位有什么帮助,没有就删掉。 3.技能特长和教育背景交换位置。 4.技能特长写的太差,上网上找简历参考。都不用问你别的,一个redis就能把你问住,写写你具体会redis哪些方面的知识。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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