vrijdag 1 juni 2007

Test Vim TOHtml

Testing VIM TOHtml, this is security bunker from SRM 269, in an effort to get friendly with Mr. Floyd & Mr. Warshall.


import static java.lang.Math.max;
import static java.lang.Math.sqrt;

public class SecurityBunker {

public double chooseBomb(String[] field) {
int R = field.length;
int C = field[0].length();

int Bomb = 0, Obj = 0;
int [] rBombs=new int[100], cBombs = new int[100];
int [] rObj =new int[100], cObj = new int[100];

for(int i=0;i<R;i++)
for(int j=0;j<C;j++)
if(field[i].charAt(j) == '*'){
rBombs[Bomb] = i;
cBombs[Bomb] = j;
Bomb ++;
} else
if(field[i].charAt(j) == '?'){
rObj[Obj] = i;
cObj[Obj] = j;
Obj ++;
}

int [] rOB = new int[Obj+Bomb];
int [] cOB = new int[Obj+Bomb];
int nOB = 0;
for(int i=0;i<Bomb;i++){
rOB[nOB] = rBombs[i];
cOB[nOB] = cBombs[i];
nOB++;
}
for(int i=0;i<Obj;i++){
rOB[nOB] = rObj[i];
cOB[nOB] = cObj[i];
nOB++;
}

int dist[][] = new int[nOB][nOB];

for(int i=0;i<nOB;i++)
for(int j=0;j<nOB;j++){
int dr = rOB[i] - rOB[j];
int dc = cOB[i] - cOB[j];
dist[i][j] = dr*dr+dc*dc;
}

for(int k=0;k<Bomb;k++)
for(int i=0;i<nOB;i++)
for(int j=0;j<Bomb;j++)
if(max(dist[i][k],dist[k][j]) < dist[i][j])
dist[i][j] = max(dist[i][k],dist[k][j]);

double res = 0;
for(int i=Bomb;i<nOB;i++)
for(int j=0;j<Bomb;j++)
res = max(res,dist[i][j]);

return sqrt(res);
}

}

Geen opmerkingen: