Source code for submission s542

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. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13.  
  14. /**
  15.  *
  16.  * @author cteam028
  17.  */
  18. public class Main {
  19.  
  20. /**
  21.   * @param args the command line arguments
  22.   */
  23. public static void main(String[] args) {
  24. try {
  25. Main fm = new Main();
  26. fm.init();
  27. } catch (IOException ex) {
  28. Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  29. }
  30. }
  31.  
  32. public void init() throws IOException{
  33. String line;
  34.  
  35. while((line = br.readLine()) != null) {
  36. String a[] = line.split(" ");
  37.  
  38. int Ar = Integer.parseInt(a[0]);
  39. int Ac = Integer.parseInt(a[1]);
  40. int Tr = Integer.parseInt(a[2]);
  41. int Tc = Integer.parseInt(a[3]);
  42.  
  43. int pole[][][][] = new int[Ar][Ac][(Ar/Tr) + 2][(Ac/Tc) + 2];
  44.  
  45. for(int x=0; x < Ar; x++) {
  46. line = br.readLine();
  47. char[] text = line.toCharArray();
  48. for(int y=0; y < Ac; y++) {
  49. boolean inMap = (text[y] == 'X');
  50. if(inMap){
  51. for (int dx = 0; dx < Tr; dx++) {
  52. for (int dy = 0; dy < Tc; dy++) {
  53. pole[dx][dy][(x + dx)/Tr][(y + dy)/Tc] = 1;
  54. }
  55. }
  56. }
  57. }
  58. }
  59.  
  60. int min = Integer.MAX_VALUE;
  61.  
  62. for (int dx = 0; dx < Tr; dx++) {
  63. for (int dy = 0; dy < Tc; dy++) {
  64. int pocet = 0;
  65. for (int idxx = 0; idxx < (Ar/Tr) + 2; idxx++) {
  66. for (int idxy = 0; idxy < (Ac/Tc) + 2; idxy++) {
  67. if(pole[dx][dy][idxx][idxy] == 1) pocet++;
  68.  
  69. }
  70. }
  71. min = Math.min(min, pocet);
  72. }
  73. }
  74.  
  75. System.out.println(min);
  76.  
  77.  
  78. }
  79. }
  80.  
  81. }
  82.