Source code for submission s576

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) {
  22. try {
  23. Main fm = new Main();
  24. fm.init();
  25. } catch (Exception ex) {
  26. //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  27. }
  28. }
  29.  
  30. public void init() throws IOException{
  31. String line;
  32.  
  33. while((line = br.readLine()) != null) {
  34. // String a[] = line.split(" ");
  35.  
  36. final int[] arr = new int[4];
  37. parseIntArr(line.toCharArray(), arr);
  38.  
  39. final int Ar = arr[0];
  40. final int Ac = arr[1];
  41. final int Tr = arr[2];
  42. final int Tc = arr[3];
  43.  
  44. // int Ar = Integer.parseInt(a[0]);
  45. // int Ac = Integer.parseInt(a[1]);
  46. // int Tr = Integer.parseInt(a[2]);
  47. // int Tc = Integer.parseInt(a[3]);
  48.  
  49. int pole[][][][] = new int[Ar][Ac][(Ar/Tr) + 2][(Ac/Tc) + 2];
  50.  
  51. for(int x=0; x < Ar; x++) {
  52. line = br.readLine();
  53. char[] text = line.toCharArray();
  54. for(int y=0; y < Ac; y++) {
  55. boolean inMap = (text[y] == 'X');
  56. if(inMap){
  57. for (int dx = 0; dx < Tr; dx++) {
  58. for (int dy = 0; dy < Tc; dy++) {
  59. pole[dx][dy][(x + dx)/Tr][(y + dy)/Tc] = 1;
  60. }
  61. }
  62. }
  63. }
  64. }
  65.  
  66. int min = Integer.MAX_VALUE;
  67.  
  68. for (int dx = 0; dx < Tr; dx++) {
  69. for (int dy = 0; dy < Tc; dy++) {
  70. int pocet = 0;
  71. for (int idxx = 0; idxx < (Ar/Tr) + 2; idxx++) {
  72. for (int idxy = 0; idxy < (Ac/Tc) + 2; idxy++) {
  73. if(pole[dx][dy][idxx][idxy] == 1) pocet++;
  74.  
  75. }
  76. }
  77. min = Math.min(min, pocet);
  78. }
  79. }
  80.  
  81. System.out.println(min);
  82.  
  83.  
  84. }
  85. }
  86.  
  87. public static void parseIntArr(char[] arr, int[] target)
  88. {
  89. int i = 0;
  90. int acc = -1;
  91.  
  92. for(char ch :arr)
  93. {
  94. if(ch == ' ')
  95. {
  96. if(acc!= -1)
  97. {
  98. target[i++] = acc;
  99. acc = -1;
  100. }
  101. }
  102. else if(acc == -1)
  103. acc = ch - '0';
  104. else
  105. acc = acc * 10 + (ch - '0');
  106. }
  107. if(acc != -1)
  108. target[i] = acc;
  109. }
  110.  
  111. }
  112.  

Diff to submission s553

Main.java

--- c5.s553.cteam028.fm.java.0.Main.java
+++ c5.s576.cteam028.fm.java.0.Main.java
@@ -9,6 +9,4 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 /**
@@ -35,10 +33,18 @@
         
         while((line = br.readLine()) != null) {
-            String a[] = line.split(" ");
+//            String a[] = line.split(" ");
 
-            int Ar = Integer.parseInt(a[0]);
-            int Ac = Integer.parseInt(a[1]);
-            int Tr = Integer.parseInt(a[2]);
-            int Tc = Integer.parseInt(a[3]);
+            final int[] arr = new int[4];
+            parseIntArr(line.toCharArray(), arr);
+            
+            final int Ar = arr[0];
+            final int Ac = arr[1];
+            final int Tr = arr[2];
+            final int Tc = arr[3];
+            
+//            int Ar = Integer.parseInt(a[0]);
+//            int Ac = Integer.parseInt(a[1]);
+//            int Tr = Integer.parseInt(a[2]);
+//            int Tc = Integer.parseInt(a[3]);
             
             int pole[][][][] = new int[Ar][Ac][(Ar/Tr) + 2][(Ac/Tc) + 2];
@@ -79,4 +85,28 @@
         }
     }
+    
+    public static void parseIntArr(char[] arr, int[] target)
+    {
+        int i = 0;
+        int acc = -1;
+        
+        for(char ch :arr)
+        {
+            if(ch == ' ')
+            {
+                if(acc!= -1)
+                {
+                    target[i++] = acc;
+                    acc = -1;
+                }
+            }
+            else if(acc == -1)
+                acc = ch - '0';
+            else
+                acc = acc * 10 + (ch - '0');
+        }
+        if(acc != -1)
+            target[i] = acc;
+    }
 
 }