Untitled
https://www.geeksforgeeks.org/samsung-interview-experience-on-campus-for-r-d-noida/ Level 4 Đảo Cột Trong ma trận nhị phân, phép đảo cột của ma trận là việc thay thế các giá trị của cột đó từ 0 -> 1 và từ 1 -> 0. Cho ma trận nhị phân NxM (N <= 100, M <= 20), hỏi sau K lần đảo cột thì số hàng gồm toàn số 1 nhiều nhất có thể thu được là bao nhiêu. (Yêu cầu phải đảo cột đúng K lần và một cột có thể được đảo nhiều lần) Ví dụ Với ví dụ bên, nếu K = 1, ta sẽ có kết quả lớn nhất khi đảo cột thứ 2 và thu được 1 hàng gồm toàn số 1 là hàng thứ 4. Nếu K = 2, kết quả thu được là 2 khi đảo cột thứ 2 và cột thứ 3. 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1 K=1, có 1 hàng toàn 1 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 0 1 1 K=2, có 2 hàng toàn 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 Input: Cho 3 số N, M, K Tiếp theo là ma trận NxM Output: In ra số lượng hàng toàn 1 nhiều nhất định dạng như bên dưới Case #1 1 Case #2 2 10 5 5 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1 5 5 2 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1 50 10 21 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 import java.util.Scanner; public class Solution { static final int NMAX = 100, MMAX = 20; static int T, N, M, K, max; static int[][] map = new int[NMAX][MMAX]; // [0 - (N-1)] static int[][] tempMap = new int[NMAX][MMAX]; // [0 - (N-1)] public static void main(String[] args) throws Exception { // System.setIn(new FileInputStream("src/APS_2111/laze.txt")); Scanner sc = new Scanner(System.in); T = sc.nextInt(); for (int tc = 1; tc <= T; tc++) { // reset max = 0; // read input N = sc.nextInt(); M = sc.nextInt(); K = sc.nextInt(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { map[i][j] = sc.nextInt(); } } // process solve(); // out System.out.printf("Case #%d %d%n", tc, max); } } private static void solve() { int count, cnt; // Duyet tung hang for (int r = 0; r < N; r++) { // Voi moi hang, copy map => tempMap de thao tac tren do copyMap(); // Khoi tao count luu so lan lat count = 0; // Lat cac cot bang 0 for (int c = 0; c < M; c++) { if (tempMap[r][c] == 0) { count++; set(c); } } // Hang r sau khi lat, all bang 1 // Kiem tra xem hang nay co the set all bang 1 voi K lan khong if (count <= K && (K - count) % 2 == 0) { cnt = calculate(); if (cnt > max) { max = cnt; } } } } private static void copyMap() { for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { tempMap[i][j] = map[i][j]; } } } private static boolean compare01(int col) { int zeroCnt = 0, oneCnt = 0; for (int i = 0; i < N; i++) { if (map[i][col] == 0) { zeroCnt++; } else { oneCnt++; } } if (zeroCnt >= oneCnt) { return true; } return false; } private static void set(int c) { int value; for (int r = 0; r < N; r++) { value = tempMap[r][c]; tempMap[r][c] = value ^ 1; } } private static int calculate() { int count = 0; FORI: for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (tempMap[i][j] == 0) { continue FORI; } } count++; } return count; } }
Leave a Comment