第一题原来是这个意思吗🥰🥰🥰,学会了
第一题:字符数组字典序 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;    }}第三题 没看
点赞 2
评论 0
全部评论

相关推荐

frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
点赞 评论 收藏
分享
05-09 12:23
已编辑
华南理工大学 Java
野猪不是猪🐗:给他装的,双九+有实习的能看的上这种厂我直接吃⑨✌们拿它练练面试愣是给他整出幻觉了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务