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; }*/ boolean xFound = false; for (int i = 0; i < rows; i++) { map[i] = nextToken(); if(!xFound){ xFound = map[i].indexOf("X") != -1; } } if(!xFound){ return true; } if(tileRows >= rows && tileCols >= cols){ return true; } /* 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 >= rows)?(1):(tileRows)); i++) { for (int j = 0; j < ((tileCols >= cols)?(1):(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.s1036.cteam007.fm.java.0.Fm.java +++ c5.s1051.cteam007.fm.java.0.Fm.java @@ -117,6 +117,6 @@ int min = Integer.MAX_VALUE; - for (int i = 0; i < tileRows; i++) { - for (int j = 0; j < tileCols; j++) { + for (int i = 0; i < ((tileRows >= rows)?(1):(tileRows)); i++) { + for (int j = 0; j < ((tileCols >= cols)?(1):(tileCols)); j++) { //System.out.println("Iteration[" + (-i) + "," + (-j) + "]"); min = Math.min(min, ts.getNumber(-i, -j));