Skip to content

Instantly share code, notes, and snippets.

@joemmanuel
Created September 30, 2013 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemmanuel/6765773 to your computer and use it in GitHub Desktop.
Save joemmanuel/6765773 to your computer and use it in GitHub Desktop.
Solución de charlyhlms a Super Nieves Bros.
#include <iostream>
using namespace std;
int vis[102][102];
int color;
int n, m;
int xf, yf;
char mapa[102][102];
void busqueda(int x, int y, int l){
if(x<=0 || y<=0 || x>n || y>m)
return;
if(vis[x][y]==color)
return;
if(mapa[x][y]=='.')
return;
vis[x][y]=color;
busqueda(x, y+1, l);
busqueda(x, y-1, l);
for(int i=1; i<=l; i++){
busqueda(x+i, y, l);
busqueda(x-i, y, l);
}
}
int main(){
cin>>n>>m;
cin>>xf>>yf;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cin>>mapa[i][j];
}
}
for(int i=0; i<=n; i++){
color++;
busqueda(n, 1, i);
if(vis[xf][yf]==color){
cout<<i<<"\n";
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment