9.6 去哪儿笔试 开发

第一题:字符数组字典序 100%

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(reader.readLine());
        String[] as = reader.readLine().split(" ");

        Arrays.sort(as, (s1, s2) -> (s1 + s2).compareTo(s2 + s1));

        for (String str : as) {
            System.out.printf("%s ", str);
        }
    }
}

第二题:二分 + 贪心 100%

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = reader.readLine().split(" ");
        int n = Integer.parseInt(inputs[0]);
        long m = Integer.parseInt(inputs[1]);
        int[] a = new int[n];
        String[] as = reader.readLine().split(" ");
        for (int i = 0; i < n; ++ i) a[i] = Integer.parseInt(as[i]);
        int[] b = new int[n];
        String[] bs = reader.readLine().split(" ");
        for (int i = 0; i < n; ++ i) b[i] = Integer.parseInt(bs[i]);

        int l = 0, r = n - 1;
        while (l <= r) {
            int mid = l + (r - l) / 2;

            if (check(mid, a, b, m)) {
                r = mid - 1;
            }
            else l = mid + 1;
        }

        System.out.println(l >= n ? -1 : (l + 1));
    }

    private static boolean check(int k, int[] a, int[] b, long limit) {
        int[] a_copy = Arrays.copyOfRange(a, 0, k + 1);
        Arrays.sort(a_copy);
        int[] b_copy = Arrays.copyOfRange(b, 0, k + 1);
        Arrays.sort(b_copy);

        long t = 0L;
        for (int i = k; i >= 0; -- i) {
            t += (long) a_copy[i] * b_copy[i];
            if (t >= limit) return true;
        }
        return false;
    }
}

第三题 没看

#去哪儿旅行秋招#
全部评论

相关推荐

07-11 10:56
门头沟学院 Java
码客明:大胆的说自己能实习6个月就行
点赞 评论 收藏
分享
Vincent777...:实习经历可以考虑放上去,对于软件使用方面可以细化一些,比如调整为:熟悉基于LSDYNA的瞬态动力学仿真分析,熟悉基于WORKBENCH的结构拓扑优化
我的简历长这样
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
评论
2
7
分享

创作者周榜

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