01 在行列都排好序的矩阵中找指定的数
Table of Contents

ac

import java.util.Scanner;

public class Main {

    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();

        int[][] matrix = new int[N][M];
        for (int i = 0; i < N; i++){
            for (int j = 0; j < M; j++){
                matrix[i][j] = sc.nextInt();
            }
        }

        boolean rs = false;
        int i = 0;
        int j = M-1;
        while (i < N && j >= 0){
            if(matrix[i][j] == K){
                rs = true;
                break;
            }else if(matrix[i][j] < K){
                i ++;
            }else {
                j--;
            }
        }
        if(rs){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }

}