Go to diff to previous submission
/* * CTU Open 2013 * HES */ package template; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * * @author cteam007 */ public class Fm { } while (!st.hasMoreTokens()) { } return st.nextToken(); } } /** * @param args the command line arguments */ Fm instance = new Fm(); while (instance.run()) { } } if (in == null) { return false; } useLine(in); int rows = nextInt(); int cols = nextInt(); int tileRows = nextInt(); int tileCols = nextInt(); /* int colsapper = Math.max(cols, tileCols); int rowsapper = Math.max(rows, tileRows); */ /* String rowAddon = ""; String colAddon = ""; String rowAddon2 = ""; for (int ra = 0; ra < colsapper; ra++) { rowAddon += "."; } for (int ra = 0; ra < tileRows; ra++) { rowAddon2 += "."; } for (int ra = 0; ra < colsapper + colsapper + cols + tileCols; ra++) { colAddon += "."; } for (int i = 0; i < rowsapper; i++) { map[i] = colAddon; } for (int i = rowsapper; i < rowsapper + rows; i++) { map[i] = rowAddon + nextToken() + rowAddon; } for (int i = rowsapper + rows; i < rows + rowsapper + rowsapper; i++) { map[i] = colAddon; }*/ for (int i = 0; i < rows; i++) { map[i] = nextToken(); } /* System.out.println(""); for(int i = 0; i < rows*3 ; i++){ System.out.println(map[i]); } System.out.println(""); * */ TileStructure ts = new TileStructure(rows, cols, tileRows, tileCols, map); for (int i = 0; i < tileRows; i++) { for (int j = 0; j < tileCols; j++) { //System.out.println("Iteration[" + (-i) + "," + (-j) + "]"); } } return true; } } class TileStructure { int tilesH; int tilesW; int tileRows; int tileCols; tilesH = rows / tileRows + ((rows % tileRows == 0) ? (0) : (1)) + 1; tilesW = cols / tileCols + ((cols % tileCols == 0) ? (0) : (1)) + 1; this.tileCols = tileCols; this.tileRows = tileRows; this.map = map; } public int getNumber(int xOffset, int yOffset) { int count = 0; for (int h = 0; h < tilesH; h++) { for (int w = 0; w < tilesW; w++) { boolean hasX = false; for (int ht = h * tileRows; ht < h * tileRows + tileRows && !hasX; ht++) { for (int wt = w * tileCols; wt < w * tileCols + tileCols && !hasX; wt++) { //System.out.print("T[" + h + "," + w + "]-[" + (ht+rows) + "," + (wt+cols) + "] = "); if((ht + xOffset >= 0) && (ht + xOffset < map.length) && (wt + yOffset >= 0) && (wt + yOffset < map[0].length())){ if (map[ht + xOffset].charAt(wt + yOffset) == 'X') { hasX = true; } } //System.out.println("X"); //}else{ //System.out.println("."); //} } } if (hasX) { count++; } } } return count; } }
--- c5.s936.cteam007.fm.java.0.Fm.java +++ c5.s1011.cteam007.fm.java.0.Fm.java @@ -56,50 +56,59 @@ int tileCols = nextInt(); - String[] map = new String[rows * 3]; + /* + int colsapper = Math.max(cols, tileCols); + int rowsapper = Math.max(rows, tileRows); + */ + String[] map = new String[rows]; //+ rowsapper + rowsapper + tileRows]; + + /* String rowAddon = ""; String colAddon = ""; - - for (int ra = 0; ra < cols; ra++) { - rowAddon += "."; + String rowAddon2 = ""; + for (int ra = 0; ra < colsapper; ra++) { + rowAddon += "."; } - - for (int ra = 0; ra < cols * 3; ra++) { - colAddon += "."; + for (int ra = 0; ra < tileRows; ra++) { + rowAddon2 += "."; } + for (int ra = 0; ra < colsapper + colsapper + cols + tileCols; ra++) { + colAddon += "."; + } + for (int i = 0; i < rowsapper; i++) { + map[i] = colAddon; + } + for (int i = rowsapper; i < rowsapper + rows; i++) { + map[i] = rowAddon + nextToken() + rowAddon; + } + for (int i = rowsapper + rows; i < rows + rowsapper + rowsapper; i++) { + map[i] = colAddon; + }*/ for (int i = 0; i < rows; i++) { - map[i] = colAddon; + map[i] = nextToken(); } - for (int i = rows; i < rows * 2; i++) { - map[i] = rowAddon + nextToken() + rowAddon; - } - - for (int i = rows*2; i < rows*3; i++) { - map[i] = colAddon; - } - /* System.out.println(""); for(int i = 0; i < rows*3 ; i++){ - System.out.println(map[i]); + System.out.println(map[i]); } System.out.println(""); * */ - + TileStructure ts = new TileStructure(rows, cols, tileRows, tileCols, map); int min = Integer.MAX_VALUE; - + for (int i = 0; i < tileRows; i++) { for (int j = 0; j < tileCols; j++) { //System.out.println("Iteration[" + (-i) + "," + (-j) + "]"); - min = Math.min(min,ts.getNumber(-i, -j)); + min = Math.min(min, ts.getNumber(-i, -j)); } } System.out.println(min); - + return true; } @@ -112,6 +121,4 @@ int tileRows; int tileCols; - int cols; - int rows; String[] map; @@ -123,7 +130,4 @@ this.tileRows = tileRows; this.map = map; - - this.cols = cols; - this.rows = rows; } @@ -137,11 +141,13 @@ for (int wt = w * tileCols; wt < w * tileCols + tileCols && !hasX; wt++) { //System.out.print("T[" + h + "," + w + "]-[" + (ht+rows) + "," + (wt+cols) + "] = "); - if (map[ht+rows+xOffset].charAt(wt+cols+yOffset) == 'X') { - hasX = true; + if((ht + xOffset >= 0) && (ht + xOffset < map.length) && (wt + yOffset >= 0) && (wt + yOffset < map[0].length())){ + if (map[ht + xOffset].charAt(wt + yOffset) == 'X') { + hasX = true; + } } - //System.out.println("X"); - //}else{ - //System.out.println("."); - //} + //System.out.println("X"); + //}else{ + //System.out.println("."); + //} } }