Source code for submission s606

Go to diff to previous submission

Main.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package folded;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11.  
  12. /**
  13.  *
  14.  * @author cteam028
  15.  */
  16. public class Main {
  17.  
  18. /**
  19.   * @param args the command line arguments
  20.   */
  21. public static void main(String[] args) throws Exception {
  22. try {
  23. Main fm = new Main();
  24. fm.init();
  25. //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  26. }
  27. }
  28.  
  29. public void init() throws IOException{
  30. String line;
  31.  
  32. while((line = br.readLine()) != null) {
  33. // String a[] = line.split(" ");
  34.  
  35. final int[] arr = new int[4];
  36. parseIntArr(line.toCharArray(), arr);
  37.  
  38. final int Ar = arr[0];
  39. final int Ac = arr[1];
  40. final int Tr = arr[2];
  41. final int Tc = arr[3];
  42.  
  43. // int Ar = Integer.parseInt(a[0]);
  44. // int Ac = Integer.parseInt(a[1]);
  45. // int Tr = Integer.parseInt(a[2]);
  46. // int Tc = Integer.parseInt(a[3]);
  47.  
  48. int pole[][][][] = new int[Tr][Tc][(Ar/Tr) + 2][(Ac/Tc) + 2];
  49.  
  50. for(int x=0; x < Ar; x++) {
  51. line = br.readLine();
  52. char[] text = line.toCharArray();
  53. for(int y=0; y < Ac; y++) {
  54. boolean inMap = (text[y] == 'X');
  55. if(inMap){
  56. for (int dx = 0; dx < Tr; dx++) {
  57. for (int dy = 0; dy < Tc; dy++) {
  58. pole[dx][dy][(x + dx)/Tr][(y + dy)/Tc] = 1;
  59. }
  60. }
  61. }
  62. }
  63. }
  64.  
  65. int min = Integer.MAX_VALUE;
  66.  
  67. for (int dx = 0; dx < Tr; dx++) {
  68. for (int dy = 0; dy < Tc; dy++) {
  69. int pocet = 0;
  70. for (int idxx = 0; idxx < (Ar/Tr) + 2; idxx++) {
  71. for (int idxy = 0; idxy < (Ac/Tc) + 2; idxy++) {
  72. if(pole[dx][dy][idxx][idxy] == 1) pocet++;
  73.  
  74. }
  75. }
  76. min = Math.min(min, pocet);
  77. }
  78. }
  79.  
  80. System.out.println(min);
  81.  
  82.  
  83. }
  84. }
  85.  
  86. public static void parseIntArr(char[] arr, int[] target)
  87. {
  88. int i = 0;
  89. int acc = -1;
  90.  
  91. for(char ch :arr)
  92. {
  93. if(ch == ' ')
  94. {
  95. if(acc!= -1)
  96. {
  97. target[i++] = acc;
  98. acc = -1;
  99. }
  100. }
  101. else if(acc == -1)
  102. acc = ch - '0';
  103. else
  104. acc = acc * 10 + (ch - '0');
  105. }
  106. if(acc != -1)
  107. target[i] = acc;
  108. }
  109.  
  110. }
  111.  

Diff to submission s576

Main.java

--- c5.s576.cteam028.fm.java.0.Main.java
+++ c5.s606.cteam028.fm.java.0.Main.java
@@ -19,9 +19,9 @@
      * @param args the command line arguments
      */
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
         try {
             Main fm = new Main();
             fm.init();
-        } catch (Exception ex) {
+        } catch (ArrayIndexOutOfBoundsException ex) {
             //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
         }
@@ -48,5 +48,5 @@
 //            int Tc = Integer.parseInt(a[3]);
             
-            int pole[][][][] = new int[Ar][Ac][(Ar/Tr) + 2][(Ac/Tc) + 2];
+            int pole[][][][] = new int[Tr][Tc][(Ar/Tr) + 2][(Ac/Tc) + 2];
             
             for(int x=0; x < Ar; x++) {