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
martinancevski's solution for 400: GivesYouWings, written in Java, submitted on 09.05.2010 13:31:25
import java.util.*; public class GivesYouWings { static int rez=Integer.MAX_VALUE; static String[] maze; static boolean[][] pominato; public static void setaj(int i,int j,int speed,int sum) { pominato[i][j]=true; if (maze[i].charAt(j)=='*') { speed/=2; } if (maze[i].charAt(j)=='T') { rez=Math.min(rez,sum); } int [] h={0,0,-1,1}; int [] v={-1,1,0,0,}; for (int p=0;p<4;p++) { int n=maze.length,m=maze[0].length(); if (i+v[p]<n && i+v[p]>=0 && j+h[p]<m && j+h[p]>=0 && sum+speed<rez && maze[i+v[p]].charAt(j+h[p])!='#' && (!pominato[i+v[p]][j+h[p]])) setaj(i+v[p],j+h[p],speed,sum+speed); } pominato[i][j]=false; } /*public class sostojba { public int i,j,speed,sum; public sostojba(int ii,int jj,int ss,int sm) { i=ii; j=jj; speed=ss; sum=sum; } }*/ public int solve(String[] maze) { this.maze=maze; int n=maze.length,m=maze[0].length(),pi=0,pj=0; pominato=new boolean[n][m]; for (int i=0;i<n;i++) for (int j=0;j<m;j++) pominato[i][j]=false; for (int i=0;i<maze.length;i++) if (maze[i].contains("S")) { setaj (i,maze[i].indexOf("S"),256,0); pi=i; pj=maze[i].indexOf("S"); } /*Queue<sostojba> redica= new LinkedList<sostojba>(); redica.add(new sostojba (pi,pj,256,0)); while (!redica.isEmpty()) { sostojba mom=redica.remove(); int i=mom.i,j=mom.j,speed=mom.speed,sum=mom.sum; if (maze[i].charAt(j)=='*') speed/=2; if (maze[i].charAt(j)=='T') rez=Math.min(rez,sum); int [] h={0,0,-1,1}; int [] v={-1,1,0,0,}; for (int p=0;p<4;p++) { if (i+v[p]<n && i+v[p]>=0 && j+h[p]<m && j+h[p]>=0 && sum+speed<rez && maze[i+v[p]].charAt(j+h[p])!='#') redica.add(new sostojba (i+v[p],j+h[p],speed,sum+speed)); } }*/ if (rez==Integer.MAX_VALUE) return -1; return rez; } }