Пример #1
0
 void pln(String s) {
   try {
     bw.write(s);
     bw.write(System.lineSeparator());
   } catch (Exception ex) {
   }
 }
Пример #2
0
  public void solve() throws Exception {

    String s = br.readLine();
    String[] sp = s.split(" ");
    int n = parseInt(sp[0]);
    int m = parseInt(sp[1]);
    int fl = 0;
    int hf = 0;
    int zr = 0;
    for (int i = 0; i < n; i++) {
      s = br.readLine();
      sp = s.split(" ");
      for (int j = 0; j < sp.length; j++) {
        if (sp[j].equals("11")) {
          fl++;
        } else if (sp[j].equals("00")) {
          zr++;
        } else {
          hf++;
        }
      }
    }
    int[][] ans = new int[n][m];
    int fla = fl % m;
    int row = 0;
    int col = 0;
    if (fl > 0) {
      for (row = 0; row < n; row++) {
        for (col = 0; col < m; col++) {
          ans[row][col] = 1;
          fl--;
          if (fl == 0) {
            break;
          }
        }
        if (fl == 0) {
          break;
        }
      }
      col++;
    }

    if (col == m) {
      row++;
      col = 0;
    }
    if (hf > 0) {
      for (int j = m - 1; j >= col; j--) {
        ans[row][j] = 2;
        hf--;
        if (hf == 0) {
          break;
        }
      }
    }
    boolean flag = true;
    for (int i = n - 1; i >= 0; i--) {
      if (hf == 0) break;
      for (int j = m - 1; j >= 0; j--) {
        if (flag) {
          ans[i][j] = 3;
        } else {
          ans[i][j] = 2;
        }
        hf--;
        if (hf == 0) break;
      }
      flag = !flag;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (j != 0) {
          bw.write(" ");
        }
        if (ans[i][j] == 1) {
          bw.write("11");
        } else if (ans[i][j] == 2) {
          bw.write("01");
        } else if (ans[i][j] == 3) {
          bw.write("10");
        } else {
          bw.write("00");
        }
      }
      bw.write("\n");
    }
  }
Пример #3
0
 void pl(String s) {
   try {
     bw.write(s);
   } catch (Exception ex) {
   }
 }