关于本题在CF官网题解找到一种新的思路
查看原帖
关于本题在CF官网题解找到一种新的思路
590609
jiangjiangQwQ楼主2023/10/17 19:46

讨论的第一条

有没有佬能好理解地解释一下这种思路。

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class A4 {

    void solve() {
        int m = cint();
        int n = cint();
        int[][] a = new int[m][n];
        int[] c = new int[n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = cint();
                c[j] = Math.max(c[j], a[i][j]);
            }
            Arrays.sort(a[i]);
        }

        int res = 0;
        for (int i = 0; i < m; i++) {
            res = Math.max(res, a[i][n-2]);
        }
        for (int i = 0; i < n; i++) {
            res = Math.min(res, c[i]);
        }
        cout(res);
    }

    public static void main(String... args) {
        int t = in.nextInt();
        for (int test = 0; test < t; test++) {
            new A4().solve();
        }
        out.flush();
    }

    static final QuickReader in = new QuickReader(System.in);
    static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, 131_072));

    static int cint() {
        return in.nextInt();
    }

    static long clong() {
        return in.nextLong();
    }

    static String cstr() {
        return in.nextLine();
    }

    static int[] carr_int(int n) {
        return in.nextInts(n);
    }

    static long[] carr_long(int n) {
        return in.nextLongs(n);
    }

    static void cout(int... a) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < a.length; i++) {
            if (i != 0) {
                buf.append(' ');
            }
            buf.append(a[i]);
        }
        out.println(buf);
    }

    static void cout(long... a) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < a.length; i++) {
            if (i != 0) {
                buf.append(' ');
            }
            buf.append(a[i]);
        }
        out.println(buf);
    }

    static void cout(Object o) {
        out.println(o);
    }

    static class QuickReader {
        BufferedReader in;
        StringTokenizer token;

        public QuickReader(InputStream ins) {
            in = new BufferedReader(new InputStreamReader(ins));
            token = new StringTokenizer("");
        }

        public boolean hasNext() {
            while (!token.hasMoreTokens()) {
                try {
                    String s = in.readLine();
                    if (s == null) {
                        return false;
                    }
                    token = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return true;
        }

        public String next() {
            hasNext();
            return token.nextToken();
        }

        public String nextLine() {
            try {
                String s = in.readLine();
                token = new StringTokenizer("");
                return s;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextInts(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] nextLongs(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextLong();
            }
            return res;
        }
    }
}
2023/10/17 19:46
加载中...