Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2010
CodeFu'10 Highlights
Jazoon'10 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2010
»
Results
CodeFu 2010 Results
Final Round Results
Zlate87's solution for 400: GivesYouWings, written in Java, submitted on 09.05.2010 13:35:52
public class GivesYouWings { char[][] charMaze; int back=-1; public int solve(String[] maze) { charMaze = new char[maze.length][maze[0].length()]; int startI = 0, startJ = 0; for (int i = 0; i < maze.length; i++) { for (int j = 0; j < maze[i].length(); j++) { charMaze[i][j] = maze[i].charAt(j); if (charMaze[i][j] == 'S') { startI = i; startJ = j; } // System.out.print(charMaze[i][j]); } // System.out.println(); } walk(0, startI, startJ, 256); return back; } public int walk(int _time, int _i, int _j, int _moveTakesSeconds) { int time=_time; int i=_i; int j=_j; int moveTakesSeconds=_moveTakesSeconds; if (charMaze[i][j] == 'T') { //time-=moveTakesSeconds; // System.out.println("T " + time + " "); if(back==(-1)) { back=time; } else { if(time<back) { back=time; } } return time; } if (charMaze[i][j] == '#' || charMaze[i][j] == '@') { // System.out.print("T " + time + " "); return -1; } if (charMaze[i][j] == '*') { moveTakesSeconds /= 2; charMaze[i][j] = '.'; reset(); } int tempTime2 = time + moveTakesSeconds; int tempTime = time + moveTakesSeconds; int tempT = Integer.MAX_VALUE; charMaze[i][j] = '@'; // System.out.println(i + " " + j + " " + tempTime); try { int t = walk(tempTime2, i, j - 1, moveTakesSeconds); if ((t < tempT && t != (-1))) { tempT = t; tempTime = t; } } catch (Exception e) { // TODO: handle exception } try { int t = walk(tempTime2, i + 1, j, moveTakesSeconds); if ((t < tempT && t != (-1))) { tempT = t; tempTime = t; } } catch (Exception e) { // TODO: handle exception } try { int t = walk(tempTime2, i, j + 1, moveTakesSeconds); if ((t < tempT) && t != (-1)) { tempT = t; tempTime = t; } } catch (Exception e) { // TODO: handle exception } try { int t = walk(tempTime2, i - 1, j, moveTakesSeconds); if ((t < tempT && t != (-1))) { tempT = t; tempTime = t; } } catch (Exception e) { // TODO: handle exception } // if (tempTime == time + moveTakesSeconds) { // return Integer.MAX_VALUE; // } return tempTime; } public void reset() { for(int i=0;i<charMaze.length;i++) for(int j=0;j<charMaze[i].length;j++) { if(charMaze[i][j]=='@') { charMaze[i][j]='.'; } } } }