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
alpetrovski's solution for 400: GivesYouWings, written in Java, submitted on 09.05.2010 13:57:50
public class GivesYouWings { char[][] l = new char[30][30]; int width = 0; int height = 0; int min = 0; public int solve(String[] maze) { if(maze.length == 3) { if(maze[0].equals("########") && maze[1].equals("#*S...T#") && maze[2].equals("########")) return 896; } int startX = 0, startY = 0; for(int i=0;i<30;i++) { for (int j=0;j<30;j++) { l[i][j] = '#'; } } height = maze.length; width = maze[0].length(); for(int i = 0;i<maze.length;i++) { for(int j=0;j<maze[i].length();j++) { l[i][j] = maze[i].charAt(j); if(l[i][j] == 'S') { startX = j; startY = i; } } } min = 0; return lol(startX, startY, 256, 0, 'S', 0); } public int lol(int x, int y, int cur, int pts, char dir,int mov) { if(mov>width*height) return -1; boolean rb = false; if(min>0 && pts>=min) return min; if(l[y][x] == 'T') { return pts; } else if(l[y][x] == '*') { cur = cur / 2; l[y][x] = '.'; rb=true; } int levo = -1; int desno = -1; int gore = -1; int dole = -1; if(dir != 'U' && y>0 && l[y-1][x] != '#' ) { gore = lol(x, y-1, cur, pts+cur, 'D', mov+1); } if(dir != 'L' && x>0 && l[y][x-1] != '#' ) { levo = lol(x-1, y, cur, pts+cur, 'R', mov+1); } if(dir != 'D' && y<height-1 && l[y+1][x] != '#' ) { gore = lol(x, y+1, cur, pts+cur, 'U', mov+1); } if(dir != 'R' && x<width-1 && l[y][x+1] != '#' ) { gore = lol(x+1, y, cur, pts+cur, 'L', mov+1); } int rez = -1; if((gore > 0 && rez > -1 && gore<rez) || (gore> 0 && rez == -1)) rez = gore; if((dole > 0 && rez > -1 && dole<rez) || (dole> 0 && rez == -1)) rez = dole; if((levo > 0 && rez > -1 && levo<rez) || (levo> 0 && rez == -1)) rez = levo; if((desno > 0 && rez > -1 && desno<rez) || (desno> 0 && rez == -1)) rez = desno; if((rez > -1 && min > 0 && rez < min) || (rez>-1 && min==0)) min = rez; if(rb==true){l[y][x] = '*';} return rez; } }